diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/CodeGen')
16 files changed, 248 insertions, 180 deletions
diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp index 27bb4ef..f8c7bcd 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp @@ -491,6 +491,8 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, /// a full-expression so that the block's cleanups are pushed at the /// right place in the stack. static void enterBlockScope(CodeGenFunction &CGF, BlockDecl *block) { + assert(CGF.HaveInsertPoint()); + // Allocate the block info and place it at the head of the list. CGBlockInfo &blockInfo = *new CGBlockInfo(block, CGF.CurFn->getName()); diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGCall.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGCall.cpp index 4455f1a..82ee4fc 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGCall.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGCall.cpp @@ -419,16 +419,37 @@ void CodeGenTypes::GetExpandedTypes(QualType type, uint64_t NumElts = AT->getSize().getZExtValue(); for (uint64_t Elt = 0; Elt < NumElts; ++Elt) GetExpandedTypes(AT->getElementType(), expandedTypes); - } else if (const RecordType *RT = type->getAsStructureType()) { + } else if (const RecordType *RT = type->getAs<RecordType>()) { const RecordDecl *RD = RT->getDecl(); assert(!RD->hasFlexibleArrayMember() && "Cannot expand structure with flexible array."); - for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); - i != e; ++i) { - const FieldDecl *FD = *i; - assert(!FD->isBitField() && - "Cannot expand structure with bit-field members."); - GetExpandedTypes(FD->getType(), expandedTypes); + if (RD->isUnion()) { + // Unions can be here only in degenerative cases - all the fields are same + // after flattening. Thus we have to use the "largest" field. + const FieldDecl *LargestFD = 0; + CharUnits UnionSize = CharUnits::Zero(); + + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e; ++i) { + const FieldDecl *FD = *i; + assert(!FD->isBitField() && + "Cannot expand structure with bit-field members."); + CharUnits FieldSize = getContext().getTypeSizeInChars(FD->getType()); + if (UnionSize < FieldSize) { + UnionSize = FieldSize; + LargestFD = FD; + } + } + if (LargestFD) + GetExpandedTypes(LargestFD->getType(), expandedTypes); + } else { + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e; ++i) { + const FieldDecl *FD = *i; + assert(!FD->isBitField() && + "Cannot expand structure with bit-field members."); + GetExpandedTypes(FD->getType(), expandedTypes); + } } } else if (const ComplexType *CT = type->getAs<ComplexType>()) { llvm::Type *EltTy = ConvertType(CT->getElementType()); @@ -443,32 +464,55 @@ CodeGenFunction::ExpandTypeFromArgs(QualType Ty, LValue LV, llvm::Function::arg_iterator AI) { assert(LV.isSimple() && "Unexpected non-simple lvalue during struct expansion."); - llvm::Value *Addr = LV.getAddress(); if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) { unsigned NumElts = AT->getSize().getZExtValue(); QualType EltTy = AT->getElementType(); for (unsigned Elt = 0; Elt < NumElts; ++Elt) { - llvm::Value *EltAddr = Builder.CreateConstGEP2_32(Addr, 0, Elt); + llvm::Value *EltAddr = Builder.CreateConstGEP2_32(LV.getAddress(), 0, Elt); LValue LV = MakeAddrLValue(EltAddr, EltTy); AI = ExpandTypeFromArgs(EltTy, LV, AI); } - } else if (const RecordType *RT = Ty->getAsStructureType()) { + } else if (const RecordType *RT = Ty->getAs<RecordType>()) { RecordDecl *RD = RT->getDecl(); - for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); - i != e; ++i) { - FieldDecl *FD = *i; - QualType FT = FD->getType(); - - // FIXME: What are the right qualifiers here? - LValue LV = EmitLValueForField(Addr, FD, 0); - AI = ExpandTypeFromArgs(FT, LV, AI); + if (RD->isUnion()) { + // Unions can be here only in degenerative cases - all the fields are same + // after flattening. Thus we have to use the "largest" field. + const FieldDecl *LargestFD = 0; + CharUnits UnionSize = CharUnits::Zero(); + + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e; ++i) { + const FieldDecl *FD = *i; + assert(!FD->isBitField() && + "Cannot expand structure with bit-field members."); + CharUnits FieldSize = getContext().getTypeSizeInChars(FD->getType()); + if (UnionSize < FieldSize) { + UnionSize = FieldSize; + LargestFD = FD; + } + } + if (LargestFD) { + // FIXME: What are the right qualifiers here? + LValue SubLV = EmitLValueForField(LV, LargestFD); + AI = ExpandTypeFromArgs(LargestFD->getType(), SubLV, AI); + } + } else { + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e; ++i) { + FieldDecl *FD = *i; + QualType FT = FD->getType(); + + // FIXME: What are the right qualifiers here? + LValue SubLV = EmitLValueForField(LV, FD); + AI = ExpandTypeFromArgs(FT, SubLV, AI); + } } } else if (const ComplexType *CT = Ty->getAs<ComplexType>()) { QualType EltTy = CT->getElementType(); - llvm::Value *RealAddr = Builder.CreateStructGEP(Addr, 0, "real"); + llvm::Value *RealAddr = Builder.CreateStructGEP(LV.getAddress(), 0, "real"); EmitStoreThroughLValue(RValue::get(AI++), MakeAddrLValue(RealAddr, EltTy)); - llvm::Value *ImagAddr = Builder.CreateStructGEP(Addr, 1, "imag"); + llvm::Value *ImagAddr = Builder.CreateStructGEP(LV.getAddress(), 1, "imag"); EmitStoreThroughLValue(RValue::get(AI++), MakeAddrLValue(ImagAddr, EltTy)); } else { EmitStoreThroughLValue(RValue::get(AI), LV); @@ -1760,26 +1804,38 @@ void CodeGenFunction::ExpandTypeToArgs(QualType Ty, RValue RV, EltRV = EmitLoadOfLValue(LV); ExpandTypeToArgs(EltTy, EltRV, Args, IRFuncTy); } - } else if (const RecordType *RT = Ty->getAsStructureType()) { + } else if (const RecordType *RT = Ty->getAs<RecordType>()) { RecordDecl *RD = RT->getDecl(); assert(RV.isAggregate() && "Unexpected rvalue during struct expansion"); - llvm::Value *Addr = RV.getAggregateAddr(); - for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); - i != e; ++i) { - FieldDecl *FD = *i; - QualType FT = FD->getType(); - - // FIXME: What are the right qualifiers here? - LValue LV = EmitLValueForField(Addr, FD, 0); - RValue FldRV; - if (FT->isAnyComplexType()) - // FIXME: Volatile? - FldRV = RValue::getComplex(LoadComplexFromAddr(LV.getAddress(), false)); - else if (CodeGenFunction::hasAggregateLLVMType(FT)) - FldRV = LV.asAggregateRValue(); - else - FldRV = EmitLoadOfLValue(LV); - ExpandTypeToArgs(FT, FldRV, Args, IRFuncTy); + LValue LV = MakeAddrLValue(RV.getAggregateAddr(), Ty); + + if (RD->isUnion()) { + const FieldDecl *LargestFD = 0; + CharUnits UnionSize = CharUnits::Zero(); + + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e; ++i) { + const FieldDecl *FD = *i; + assert(!FD->isBitField() && + "Cannot expand structure with bit-field members."); + CharUnits FieldSize = getContext().getTypeSizeInChars(FD->getType()); + if (UnionSize < FieldSize) { + UnionSize = FieldSize; + LargestFD = FD; + } + } + if (LargestFD) { + RValue FldRV = EmitRValueForField(LV, LargestFD); + ExpandTypeToArgs(LargestFD->getType(), FldRV, Args, IRFuncTy); + } + } else { + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e; ++i) { + FieldDecl *FD = *i; + + RValue FldRV = EmitRValueForField(LV, FD); + ExpandTypeToArgs(FD->getType(), FldRV, Args, IRFuncTy); + } } } else if (Ty->isAnyComplexType()) { ComplexPairTy CV = RV.getComplexVal(); diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGClass.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGClass.cpp index 6303e20..2aedf95 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGClass.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGClass.cpp @@ -555,15 +555,17 @@ static void EmitMemberInitializer(CodeGenFunction &CGF, QualType FieldType = Field->getType(); llvm::Value *ThisPtr = CGF.LoadCXXThis(); + QualType RecordTy = CGF.getContext().getTypeDeclType(ClassDecl); LValue LHS; - + // If we are initializing an anonymous union field, drill down to the field. if (MemberInit->isIndirectMemberInitializer()) { LHS = CGF.EmitLValueForAnonRecordField(ThisPtr, MemberInit->getIndirectMember(), 0); FieldType = MemberInit->getIndirectMember()->getAnonField()->getType(); } else { - LHS = CGF.EmitLValueForFieldInitialization(ThisPtr, Field, 0); + LValue ThisLHSLV = CGF.MakeNaturalAlignAddrLValue(ThisPtr, RecordTy); + LHS = CGF.EmitLValueForFieldInitialization(ThisLHSLV, Field); } // Special case: if we are in a copy or move constructor, and we are copying @@ -585,7 +587,8 @@ static void EmitMemberInitializer(CodeGenFunction &CGF, unsigned SrcArgIndex = Args.size() - 1; llvm::Value *SrcPtr = CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(Args[SrcArgIndex])); - LValue Src = CGF.EmitLValueForFieldInitialization(SrcPtr, Field, 0); + LValue ThisRHSLV = CGF.MakeNaturalAlignAddrLValue(SrcPtr, RecordTy); + LValue Src = CGF.EmitLValueForFieldInitialization(ThisRHSLV, Field); // Copy the aggregate. CGF.EmitAggregateCopy(LHS.getAddress(), Src.getAddress(), FieldType, @@ -978,7 +981,9 @@ namespace { void Emit(CodeGenFunction &CGF, Flags flags) { // Find the address of the field. llvm::Value *thisValue = CGF.LoadCXXThis(); - LValue LV = CGF.EmitLValueForField(thisValue, field, /*CVRQualifiers=*/0); + QualType RecordTy = CGF.getContext().getTagDeclType(field->getParent()); + LValue ThisLV = CGF.MakeAddrLValue(thisValue, RecordTy); + LValue LV = CGF.EmitLValueForField(ThisLV, field); assert(LV.isSimple()); CGF.emitDestroy(LV.getAddress(), field->getType(), destroyer, diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp index 7301d20..d286d24 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp @@ -184,7 +184,6 @@ CGDebugInfo::getClassName(const RecordDecl *RD) { const TemplateArgument *Args; unsigned NumArgs; - std::string Buffer; if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) { const TemplateSpecializationType *TST = cast<TemplateSpecializationType>(TAW->getType()); @@ -195,16 +194,17 @@ CGDebugInfo::getClassName(const RecordDecl *RD) { Args = TemplateArgs.data(); NumArgs = TemplateArgs.size(); } - Buffer = RD->getIdentifier()->getNameStart(); + StringRef Name = RD->getIdentifier()->getName(); PrintingPolicy Policy(CGM.getLangOpts()); - Buffer += TemplateSpecializationType::PrintTemplateArgumentList(Args, - NumArgs, - Policy); + std::string TemplateArgList = + TemplateSpecializationType::PrintTemplateArgumentList(Args, NumArgs, Policy); // Copy this name on the side and use its reference. - char *StrPtr = DebugInfoNames.Allocate<char>(Buffer.length()); - memcpy(StrPtr, Buffer.data(), Buffer.length()); - return StringRef(StrPtr, Buffer.length()); + size_t Length = Name.size() + TemplateArgList.size(); + char *StrPtr = DebugInfoNames.Allocate<char>(Length); + memcpy(StrPtr, Name.data(), Name.size()); + memcpy(StrPtr + Name.size(), TemplateArgList.data(), TemplateArgList.size()); + return StringRef(StrPtr, Length); } /// getOrCreateFile - Get the file debug info descriptor for the input location. diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGDecl.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGDecl.cpp index 8c154f0..6447779 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGDecl.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGDecl.cpp @@ -1171,6 +1171,10 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) { // If this was emitted as a global constant, we're done. if (emission.wasEmittedAsGlobal()) return; + // If we don't have an insertion point, we're done. Sema prevents + // us from jumping into any of these scopes anyway. + if (!HaveInsertPoint()) return; + const VarDecl &D = *emission.Variable; // Check the type for a cleanup. diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGExpr.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGExpr.cpp index 08970fd..5f2b1f0 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGExpr.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGExpr.cpp @@ -24,6 +24,7 @@ #include "clang/Frontend/CodeGenOptions.h" #include "llvm/Intrinsics.h" #include "llvm/LLVMContext.h" +#include "llvm/Support/MDBuilder.h" #include "llvm/Target/TargetData.h" using namespace clang; using namespace CodeGen; @@ -398,8 +399,8 @@ EmitExprForReferenceBinding(CodeGenFunction &CGF, const Expr *E, break; case SubobjectAdjustment::FieldAdjustment: { - LValue LV = - CGF.EmitLValueForField(Object, Adjustment.Field, 0); + LValue LV = CGF.MakeAddrLValue(Object, E->getType()); + LV = CGF.EmitLValueForField(LV, Adjustment.Field); if (LV.isSimple()) { Object = LV.getAddress(); break; @@ -908,16 +909,8 @@ llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(QualType Ty) { } } - if (End == Min) - return NULL; - - llvm::Value *LowAndHigh[2]; - LowAndHigh[0] = llvm::ConstantInt::get(LTy, Min); - LowAndHigh[1] = llvm::ConstantInt::get(LTy, End); - - llvm::LLVMContext &C = getLLVMContext(); - llvm::MDNode *Range = llvm::MDNode::get(C, LowAndHigh); - return Range; + llvm::MDBuilder MDHelper(getLLVMContext()); + return MDHelper.createRange(Min, End); } llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, @@ -1577,8 +1570,12 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { // Use special handling for lambdas. if (!V) { - if (FieldDecl *FD = LambdaCaptureFields.lookup(VD)) - return EmitLValueForField(CXXABIThisValue, FD, 0); + if (FieldDecl *FD = LambdaCaptureFields.lookup(VD)) { + QualType LambdaTagType = getContext().getTagDeclType(FD->getParent()); + LValue LambdaLV = MakeNaturalAlignAddrLValue(CXXABIThisValue, + LambdaTagType); + return EmitLValueForField(LambdaLV, FD); + } assert(isa<BlockDecl>(CurCodeDecl) && E->refersToEnclosingLocal()); CharUnits alignment = getContext().getDeclAlign(VD); @@ -1973,32 +1970,19 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) { } LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { - bool isNonGC = false; Expr *BaseExpr = E->getBase(); - llvm::Value *BaseValue = NULL; - Qualifiers BaseQuals; // If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar. - if (E->isArrow()) { - BaseValue = EmitScalarExpr(BaseExpr); - const PointerType *PTy = - BaseExpr->getType()->getAs<PointerType>(); - BaseQuals = PTy->getPointeeType().getQualifiers(); - } else { - LValue BaseLV = EmitLValue(BaseExpr); - if (BaseLV.isNonGC()) - isNonGC = true; - // FIXME: this isn't right for bitfields. - BaseValue = BaseLV.getAddress(); - QualType BaseTy = BaseExpr->getType(); - BaseQuals = BaseTy.getQualifiers(); - } + LValue BaseLV; + if (E->isArrow()) + BaseLV = MakeNaturalAlignAddrLValue(EmitScalarExpr(BaseExpr), + BaseExpr->getType()->getPointeeType()); + else + BaseLV = EmitLValue(BaseExpr); NamedDecl *ND = E->getMemberDecl(); if (FieldDecl *Field = dyn_cast<FieldDecl>(ND)) { - LValue LV = EmitLValueForField(BaseValue, Field, - BaseQuals.getCVRQualifiers()); - LV.setNonGC(isNonGC); + LValue LV = EmitLValueForField(BaseLV, Field); setObjCGCLValueClass(getContext(), E, LV); return LV; } @@ -2032,8 +2016,10 @@ LValue CodeGenFunction::EmitLValueForAnonRecordField(llvm::Value *BaseValue, IndirectFieldDecl::chain_iterator I = Field->chain_begin(), IEnd = Field->chain_end(); while (true) { - LValue LV = EmitLValueForField(BaseValue, cast<FieldDecl>(*I), - CVRQualifiers); + QualType RecordTy = + getContext().getTypeDeclType(cast<FieldDecl>(*I)->getParent()); + LValue LV = EmitLValueForField(MakeAddrLValue(BaseValue, RecordTy), + cast<FieldDecl>(*I)); if (++I == IEnd) return LV; assert(LV.isSimple()); @@ -2042,19 +2028,25 @@ LValue CodeGenFunction::EmitLValueForAnonRecordField(llvm::Value *BaseValue, } } -LValue CodeGenFunction::EmitLValueForField(llvm::Value *baseAddr, - const FieldDecl *field, - unsigned cvr) { +LValue CodeGenFunction::EmitLValueForField(LValue base, + const FieldDecl *field) { if (field->isBitField()) - return EmitLValueForBitfield(baseAddr, field, cvr); + return EmitLValueForBitfield(base.getAddress(), field, + base.getVRQualifiers()); const RecordDecl *rec = field->getParent(); QualType type = field->getType(); CharUnits alignment = getContext().getDeclAlign(field); + // FIXME: It should be impossible to have an LValue without alignment for a + // complete type. + if (!base.getAlignment().isZero()) + alignment = std::min(alignment, base.getAlignment()); + bool mayAlias = rec->hasAttr<MayAliasAttr>(); - llvm::Value *addr = baseAddr; + llvm::Value *addr = base.getAddress(); + unsigned cvr = base.getVRQualifiers(); if (rec->isUnion()) { // For unions, there is no pointer adjustment. assert(!type->isReferenceType() && "union has reference member"); @@ -2117,30 +2109,33 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value *baseAddr, } LValue -CodeGenFunction::EmitLValueForFieldInitialization(llvm::Value *BaseValue, - const FieldDecl *Field, - unsigned CVRQualifiers) { +CodeGenFunction::EmitLValueForFieldInitialization(LValue Base, + const FieldDecl *Field) { QualType FieldType = Field->getType(); if (!FieldType->isReferenceType()) - return EmitLValueForField(BaseValue, Field, CVRQualifiers); + return EmitLValueForField(Base, Field); const CGRecordLayout &RL = CGM.getTypes().getCGRecordLayout(Field->getParent()); unsigned idx = RL.getLLVMFieldNo(Field); - llvm::Value *V = Builder.CreateStructGEP(BaseValue, idx); + llvm::Value *V = Builder.CreateStructGEP(Base.getAddress(), idx); assert(!FieldType.getObjCGCAttr() && "fields cannot have GC attrs"); - // Make sure that the address is pointing to the right type. This is critical // for both unions and structs. A union needs a bitcast, a struct element // will need a bitcast if the LLVM type laid out doesn't match the desired // type. llvm::Type *llvmType = ConvertTypeForMem(FieldType); - unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace(); - V = Builder.CreateBitCast(V, llvmType->getPointerTo(AS)); - + V = EmitBitCastOfLValueToProperType(*this, V, llvmType, Field->getName()); + CharUnits Alignment = getContext().getDeclAlign(Field); + + // FIXME: It should be impossible to have an LValue without alignment for a + // complete type. + if (!Base.getAlignment().isZero()) + Alignment = std::min(Alignment, Base.getAlignment()); + return MakeAddrLValue(V, FieldType, Alignment); } @@ -2378,6 +2373,19 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( return MakeAddrLValue(RV.getScalarVal(), E->getType()); } +RValue CodeGenFunction::EmitRValueForField(LValue LV, + const FieldDecl *FD) { + QualType FT = FD->getType(); + LValue FieldLV = EmitLValueForField(LV, FD); + if (FT->isAnyComplexType()) + return RValue::getComplex( + LoadComplexFromAddr(FieldLV.getAddress(), + FieldLV.isVolatileQualified())); + else if (CodeGenFunction::hasAggregateLLVMType(FT)) + return FieldLV.asAggregateRValue(); + + return EmitLoadOfLValue(FieldLV); +} //===--------------------------------------------------------------------===// // Expression Emission @@ -3158,11 +3166,10 @@ void CodeGenFunction::SetFPAccuracy(llvm::Value *Val, float Accuracy) { if (Accuracy == 0.0 || !isa<llvm::Instruction>(Val)) return; - llvm::Value *ULPs = llvm::ConstantFP::get(Builder.getFloatTy(), Accuracy); - llvm::MDNode *Node = llvm::MDNode::get(getLLVMContext(), ULPs); + llvm::MDBuilder MDHelper(getLLVMContext()); + llvm::MDNode *Node = MDHelper.createFPMath(Accuracy); - cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpaccuracy, - Node); + cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpmath, Node); } namespace { diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp index b6efc1c..7b0e0f5 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp @@ -238,7 +238,10 @@ void AggExprEmitter::EmitMoveFromReturnSlot(const Expr *E, RValue Src) { // Otherwise, do a final copy, assert(Dest.getAddr() != Src.getAggregateAddr()); - EmitFinalDestCopy(E, Src, /*Ignore*/ true); + std::pair<CharUnits, CharUnits> TypeInfo = + CGF.getContext().getTypeInfoInChars(E->getType()); + CharUnits Alignment = std::min(TypeInfo.second, Dest.getAlignment()); + EmitFinalDestCopy(E, Src, /*Ignore*/ true, Alignment.getQuantity()); } /// EmitFinalDestCopy - Perform the final copy to DestPtr, if desired. @@ -348,7 +351,8 @@ void AggExprEmitter::EmitStdInitializerList(llvm::Value *destPtr, CGF.ErrorUnsupported(initList, "weird std::initializer_list"); return; } - LValue start = CGF.EmitLValueForFieldInitialization(destPtr, *field, 0); + LValue DestLV = CGF.MakeNaturalAlignAddrLValue(destPtr, initList->getType()); + LValue start = CGF.EmitLValueForFieldInitialization(DestLV, *field); llvm::Value *arrayStart = Builder.CreateStructGEP(alloc, 0, "arraystart"); CGF.EmitStoreThroughLValue(RValue::get(arrayStart), start); ++field; @@ -357,7 +361,7 @@ void AggExprEmitter::EmitStdInitializerList(llvm::Value *destPtr, CGF.ErrorUnsupported(initList, "weird std::initializer_list"); return; } - LValue endOrLength = CGF.EmitLValueForFieldInitialization(destPtr, *field, 0); + LValue endOrLength = CGF.EmitLValueForFieldInitialization(DestLV, *field); if (ctx.hasSameType(field->getType(), elementPtr)) { // End pointer. llvm::Value *arrayEnd = Builder.CreateStructGEP(alloc,numInits, "arrayend"); @@ -912,28 +916,24 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { return; } - llvm::Value *DestPtr = EnsureSlot(E->getType()).getAddr(); + AggValueSlot Dest = EnsureSlot(E->getType()); + LValue DestLV = CGF.MakeAddrLValue(Dest.getAddr(), E->getType(), + Dest.getAlignment()); // Handle initialization of an array. if (E->getType()->isArrayType()) { - if (E->getNumInits() > 0) { - QualType T1 = E->getType(); - QualType T2 = E->getInit(0)->getType(); - if (CGF.getContext().hasSameUnqualifiedType(T1, T2)) { - EmitAggLoadOfLValue(E->getInit(0)); - return; - } - } + if (E->isStringLiteralInit()) + return Visit(E->getInit(0)); QualType elementType = CGF.getContext().getAsArrayType(E->getType())->getElementType(); llvm::PointerType *APType = - cast<llvm::PointerType>(DestPtr->getType()); + cast<llvm::PointerType>(Dest.getAddr()->getType()); llvm::ArrayType *AType = cast<llvm::ArrayType>(APType->getElementType()); - EmitArrayInit(DestPtr, AType, elementType, E); + EmitArrayInit(Dest.getAddr(), AType, elementType, E); return; } @@ -966,7 +966,7 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // FIXME: volatility FieldDecl *Field = E->getInitializedFieldInUnion(); - LValue FieldLoc = CGF.EmitLValueForFieldInitialization(DestPtr, Field, 0); + LValue FieldLoc = CGF.EmitLValueForFieldInitialization(DestLV, Field); if (NumInitElements) { // Store the initializer into the field EmitInitializationToLValue(E->getInit(0), FieldLoc); @@ -1004,8 +1004,8 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { CGF.getTypes().isZeroInitializable(E->getType())) break; - // FIXME: volatility - LValue LV = CGF.EmitLValueForFieldInitialization(DestPtr, *field, 0); + + LValue LV = CGF.EmitLValueForFieldInitialization(DestLV, *field); // We never generate write-barries for initialized fields. LV.setNonGC(true); diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp index d3ba770..c69c883 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp @@ -1815,13 +1815,16 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(llvm::Value *Value, void CodeGenFunction::EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Slot) { RunCleanupsScope Scope(*this); + LValue SlotLV = MakeAddrLValue(Slot.getAddr(), E->getType(), + Slot.getAlignment()); CXXRecordDecl::field_iterator CurField = E->getLambdaClass()->field_begin(); for (LambdaExpr::capture_init_iterator i = E->capture_init_begin(), e = E->capture_init_end(); i != e; ++i, ++CurField) { // Emit initialization - LValue LV = EmitLValueForFieldInitialization(Slot.getAddr(), *CurField, 0); + + LValue LV = EmitLValueForFieldInitialization(SlotLV, *CurField); ArrayRef<VarDecl *> ArrayIndexes; if (CurField->getType()->isArrayType()) ArrayIndexes = E->getCaptureInitIndexVars(i); diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGExprConstant.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGExprConstant.cpp index d528e0c..bc9f9ef 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGExprConstant.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGExprConstant.cpp @@ -758,17 +758,13 @@ public: } llvm::Constant *EmitArrayInitialization(InitListExpr *ILE) { - unsigned NumInitElements = ILE->getNumInits(); - if (NumInitElements == 1 && - CGM.getContext().hasSameUnqualifiedType(ILE->getType(), - ILE->getInit(0)->getType()) && - (isa<StringLiteral>(ILE->getInit(0)) || - isa<ObjCEncodeExpr>(ILE->getInit(0)))) + if (ILE->isStringLiteralInit()) return Visit(ILE->getInit(0)); llvm::ArrayType *AType = cast<llvm::ArrayType>(ConvertType(ILE->getType())); llvm::Type *ElemTy = AType->getElementType(); + unsigned NumInitElements = ILE->getNumInits(); unsigned NumElements = AType->getNumElements(); // Initialising an array requires us to automatically diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGStmt.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGStmt.cpp index bf42dcb..a1d0789 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGStmt.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGStmt.cpp @@ -79,6 +79,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::CompoundStmtClass: case Stmt::DeclStmtClass: case Stmt::LabelStmtClass: + case Stmt::AttributedStmtClass: case Stmt::GotoStmtClass: case Stmt::BreakStmtClass: case Stmt::ContinueStmtClass: @@ -173,6 +174,8 @@ bool CodeGenFunction::EmitSimpleStmt(const Stmt *S) { case Stmt::CompoundStmtClass: EmitCompoundStmt(cast<CompoundStmt>(*S)); break; case Stmt::DeclStmtClass: EmitDeclStmt(cast<DeclStmt>(*S)); break; case Stmt::LabelStmtClass: EmitLabelStmt(cast<LabelStmt>(*S)); break; + case Stmt::AttributedStmtClass: + EmitAttributedStmt(cast<AttributedStmt>(*S)); break; case Stmt::GotoStmtClass: EmitGotoStmt(cast<GotoStmt>(*S)); break; case Stmt::BreakStmtClass: EmitBreakStmt(cast<BreakStmt>(*S)); break; case Stmt::ContinueStmtClass: EmitContinueStmt(cast<ContinueStmt>(*S)); break; @@ -332,6 +335,10 @@ void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) { EmitStmt(S.getSubStmt()); } +void CodeGenFunction::EmitAttributedStmt(const AttributedStmt &S) { + EmitStmt(S.getSubStmt()); +} + void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) { // If this code is reachable then emit a stop point (if generating // debug info). We have to do this ourselves because we are on the diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp index 06e90b6..2939062 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp @@ -22,8 +22,9 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/StmtCXX.h" #include "clang/Frontend/CodeGenOptions.h" -#include "llvm/Target/TargetData.h" #include "llvm/Intrinsics.h" +#include "llvm/Support/MDBuilder.h" +#include "llvm/Target/TargetData.h" using namespace clang; using namespace CodeGen; @@ -362,8 +363,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, LambdaThisCaptureField); if (LambdaThisCaptureField) { // If this lambda captures this, load it. - LValue ThisLValue = EmitLValueForField(CXXABIThisValue, - LambdaThisCaptureField, 0); + QualType LambdaTagType = + getContext().getTagDeclType(LambdaThisCaptureField->getParent()); + LValue LambdaLV = MakeNaturalAlignAddrLValue(CXXABIThisValue, + LambdaTagType); + LValue ThisLValue = EmitLValueForField(LambdaLV, + LambdaThisCaptureField); CXXThisValue = EmitLoadOfLValue(ThisLValue).getScalarVal(); } } else { diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.h b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.h index 3e0cd14..83f1e2d 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.h +++ b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenFunction.h @@ -1948,6 +1948,7 @@ public: void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt. void EmitLabelStmt(const LabelStmt &S); + void EmitAttributedStmt(const AttributedStmt &S); void EmitGotoStmt(const GotoStmt &S); void EmitIndirectGotoStmt(const IndirectGotoStmt &S); void EmitIfStmt(const IfStmt &S); @@ -2104,6 +2105,8 @@ public: LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e); + RValue EmitRValueForField(LValue LV, const FieldDecl *FD); + class ConstantEmission { llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference; ConstantEmission(llvm::Constant *C, bool isReference) @@ -2143,15 +2146,13 @@ public: LValue EmitLValueForAnonRecordField(llvm::Value* Base, const IndirectFieldDecl* Field, unsigned CVRQualifiers); - LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field, - unsigned CVRQualifiers); + LValue EmitLValueForField(LValue Base, const FieldDecl* Field); /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that /// if the Field is a reference, this will return the address of the reference /// and not the address of the value stored in the reference. - LValue EmitLValueForFieldInitialization(llvm::Value* Base, - const FieldDecl* Field, - unsigned CVRQualifiers); + LValue EmitLValueForFieldInitialization(LValue Base, + const FieldDecl* Field); LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value* Base, const ObjCIvarDecl *Ivar, diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp index c0ccf4d..9a55c08 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp @@ -1241,7 +1241,7 @@ CodeGenModule::CreateOrReplaceCXXRuntimeVariable(StringRef Name, /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the /// given global variable. If Ty is non-null and if the global doesn't exist, -/// then it will be greated with the specified type instead of whatever the +/// then it will be created with the specified type instead of whatever the /// normal requested type would be. llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty) { diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.cpp index 9ee3f1d..a3cadcf 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -28,7 +28,7 @@ using namespace CodeGen; CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext& VMContext, const LangOptions &Features, MangleContext &MContext) : Context(Ctx), VMContext(VMContext), Features(Features), MContext(MContext), - Root(0), Char(0) { + MDHelper(VMContext), Root(0), Char(0) { } CodeGenTBAA::~CodeGenTBAA() { @@ -40,7 +40,7 @@ llvm::MDNode *CodeGenTBAA::getRoot() { // (or a different version of this front-end), their TBAA trees will // remain distinct, and the optimizer will treat them conservatively. if (!Root) - Root = getTBAAInfoForNamedType("Simple C/C++ TBAA", 0); + Root = MDHelper.createTBAARoot("Simple C/C++ TBAA"); return Root; } @@ -51,33 +51,11 @@ llvm::MDNode *CodeGenTBAA::getChar() { // these special powers only cover user-accessible memory, and doesn't // include things like vtables. if (!Char) - Char = getTBAAInfoForNamedType("omnipotent char", getRoot()); + Char = MDHelper.createTBAANode("omnipotent char", getRoot()); return Char; } -/// getTBAAInfoForNamedType - Create a TBAA tree node with the given string -/// as its identifier, and the given Parent node as its tree parent. -llvm::MDNode *CodeGenTBAA::getTBAAInfoForNamedType(StringRef NameStr, - llvm::MDNode *Parent, - bool Readonly) { - // Currently there is only one flag defined - the readonly flag. - llvm::Value *Flags = 0; - if (Readonly) - Flags = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), true); - - // Set up the mdnode operand list. - llvm::Value *Ops[] = { - llvm::MDString::get(VMContext, NameStr), - Parent, - Flags - }; - - // Create the mdnode. - unsigned Len = llvm::array_lengthof(Ops) - !Flags; - return llvm::MDNode::get(VMContext, llvm::makeArrayRef(Ops, Len)); -} - static bool TypeHasMayAlias(QualType QTy) { // Tagged types have declarations, and therefore may have attributes. if (const TagType *TTy = dyn_cast<TagType>(QTy)) @@ -137,7 +115,7 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) { // "underlying types". default: return MetadataCache[Ty] = - getTBAAInfoForNamedType(BTy->getName(Features), getChar()); + MDHelper.createTBAANode(BTy->getName(Features), getChar()); } } @@ -145,7 +123,7 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) { // TODO: Implement C++'s type "similarity" and consider dis-"similar" // pointers distinct. if (Ty->isPointerType()) - return MetadataCache[Ty] = getTBAAInfoForNamedType("any pointer", + return MetadataCache[Ty] = MDHelper.createTBAANode("any pointer", getChar()); // Enum types are distinct types. In C++ they have "underlying types", @@ -173,7 +151,7 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) { llvm::raw_svector_ostream Out(OutName); MContext.mangleCXXRTTIName(QualType(ETy, 0), Out); Out.flush(); - return MetadataCache[Ty] = getTBAAInfoForNamedType(OutName, getChar()); + return MetadataCache[Ty] = MDHelper.createTBAANode(OutName, getChar()); } // For now, handle any other kind of type conservatively. @@ -181,5 +159,5 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) { } llvm::MDNode *CodeGenTBAA::getTBAAInfoForVTablePtr() { - return getTBAAInfoForNamedType("vtable pointer", getRoot()); + return MDHelper.createTBAANode("vtable pointer", getRoot()); } diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.h b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.h index 8e08498..4a97852 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.h +++ b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenTBAA.h @@ -17,6 +17,7 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/Support/MDBuilder.h" namespace llvm { class LLVMContext; @@ -41,6 +42,9 @@ class CodeGenTBAA { const LangOptions &Features; MangleContext &MContext; + // MDHelper - Helper for creating metadata. + llvm::MDBuilder MDHelper; + /// MetadataCache - This maps clang::Types to llvm::MDNodes describing them. llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache; @@ -55,10 +59,6 @@ class CodeGenTBAA { /// considered to be equivalent to it. llvm::MDNode *getChar(); - llvm::MDNode *getTBAAInfoForNamedType(StringRef NameStr, - llvm::MDNode *Parent, - bool Readonly = false); - public: CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext, const LangOptions &Features, diff --git a/contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp b/contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp index 3ed1778..2b71fdd 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp @@ -2527,19 +2527,16 @@ void ARMABIInfo::computeInfo(CGFunctionInfo &FI) const { static bool isHomogeneousAggregate(QualType Ty, const Type *&Base, ASTContext &Context, uint64_t *HAMembers = 0) { - uint64_t Members; + uint64_t Members = 0; if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) { if (!isHomogeneousAggregate(AT->getElementType(), Base, Context, &Members)) return false; Members *= AT->getSize().getZExtValue(); } else if (const RecordType *RT = Ty->getAs<RecordType>()) { const RecordDecl *RD = RT->getDecl(); - if (RD->isUnion() || RD->hasFlexibleArrayMember()) + if (RD->hasFlexibleArrayMember()) return false; - if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { - if (!CXXRD->isAggregate()) - return false; - } + Members = 0; for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i) { @@ -2547,7 +2544,9 @@ static bool isHomogeneousAggregate(QualType Ty, const Type *&Base, uint64_t FldMembers; if (!isHomogeneousAggregate(FD->getType(), Base, Context, &FldMembers)) return false; - Members += FldMembers; + + Members = (RD->isUnion() ? + std::max(Members, FldMembers) : Members + FldMembers); } } else { Members = 1; @@ -2584,7 +2583,8 @@ static bool isHomogeneousAggregate(QualType Ty, const Type *&Base, // Homogeneous Aggregates can have at most 4 members of the base type. if (HAMembers) *HAMembers = Members; - return (Members <= 4); + + return (Members > 0 && Members <= 4); } ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty) const { @@ -2609,8 +2609,10 @@ ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty) const { if (getABIKind() == ARMABIInfo::AAPCS_VFP) { // Homogeneous Aggregates need to be expanded. const Type *Base = 0; - if (isHomogeneousAggregate(Ty, Base, getContext())) + if (isHomogeneousAggregate(Ty, Base, getContext())) { + assert(Base && "Base class should be set for homogeneous aggregate"); return ABIArgInfo::getExpand(); + } } // Otherwise, pass by coercing to a structure of the appropriate size. @@ -2776,9 +2778,11 @@ ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy) const { // Check for homogeneous aggregates with AAPCS-VFP. if (getABIKind() == AAPCS_VFP) { const Type *Base = 0; - if (isHomogeneousAggregate(RetTy, Base, getContext())) + if (isHomogeneousAggregate(RetTy, Base, getContext())) { + assert(Base && "Base class should be set for homogeneous aggregate"); // Homogeneous Aggregates are returned directly. return ABIArgInfo::getDirect(); + } } // Aggregates <= 4 bytes are returned in r0; other aggregates |