diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-02-19 15:41:54 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-02-19 15:41:54 +0000 |
commit | 924db71fc8f6076c532c8c2ae93acc7f477452c8 (patch) | |
tree | 54a09bfcb32ccf5c8f4a4aec47a2b2cef7519efb /lib/CodeGen/CGClass.cpp | |
parent | 24fe798fffc1748d8bce1321af42981c3719cb85 (diff) |
Make std::initializer_list member initializers 'work'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGClass.cpp')
-rw-r--r-- | lib/CodeGen/CGClass.cpp | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index 7b492fba17..f269b675a0 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -418,40 +418,46 @@ static void EmitAggMemberInitializer(CodeGenFunction &CGF, ArrayRef<VarDecl *> ArrayIndexes, unsigned Index) { if (Index == ArrayIndexes.size()) { - CodeGenFunction::RunCleanupsScope Cleanups(CGF); - LValue LV = LHS; - if (ArrayIndexVar) { - // If we have an array index variable, load it and use it as an offset. - // Then, increment the value. - llvm::Value *Dest = LHS.getAddress(); - llvm::Value *ArrayIndex = CGF.Builder.CreateLoad(ArrayIndexVar); - Dest = CGF.Builder.CreateInBoundsGEP(Dest, ArrayIndex, "destaddress"); - llvm::Value *Next = llvm::ConstantInt::get(ArrayIndex->getType(), 1); - Next = CGF.Builder.CreateAdd(ArrayIndex, Next, "inc"); - CGF.Builder.CreateStore(Next, ArrayIndexVar); - - // Update the LValue. - LV.setAddress(Dest); - CharUnits Align = CGF.getContext().getTypeAlignInChars(T); - LV.setAlignment(std::min(Align, LV.getAlignment())); - } + { // Scope for Cleanups. + CodeGenFunction::RunCleanupsScope Cleanups(CGF); + + if (ArrayIndexVar) { + // If we have an array index variable, load it and use it as an offset. + // Then, increment the value. + llvm::Value *Dest = LHS.getAddress(); + llvm::Value *ArrayIndex = CGF.Builder.CreateLoad(ArrayIndexVar); + Dest = CGF.Builder.CreateInBoundsGEP(Dest, ArrayIndex, "destaddress"); + llvm::Value *Next = llvm::ConstantInt::get(ArrayIndex->getType(), 1); + Next = CGF.Builder.CreateAdd(ArrayIndex, Next, "inc"); + CGF.Builder.CreateStore(Next, ArrayIndexVar); + + // Update the LValue. + LV.setAddress(Dest); + CharUnits Align = CGF.getContext().getTypeAlignInChars(T); + LV.setAlignment(std::min(Align, LV.getAlignment())); + } - if (!CGF.hasAggregateLLVMType(T)) { - CGF.EmitScalarInit(Init, /*decl*/ 0, LV, false); - } else if (T->isAnyComplexType()) { - CGF.EmitComplexExprIntoAddr(Init, LV.getAddress(), - LV.isVolatileQualified()); - } else { - AggValueSlot Slot = - AggValueSlot::forLValue(LV, - AggValueSlot::IsDestructed, - AggValueSlot::DoesNotNeedGCBarriers, - AggValueSlot::IsNotAliased); - - CGF.EmitAggExpr(Init, Slot); + if (!CGF.hasAggregateLLVMType(T)) { + CGF.EmitScalarInit(Init, /*decl*/ 0, LV, false); + } else if (T->isAnyComplexType()) { + CGF.EmitComplexExprIntoAddr(Init, LV.getAddress(), + LV.isVolatileQualified()); + } else { + AggValueSlot Slot = + AggValueSlot::forLValue(LV, + AggValueSlot::IsDestructed, + AggValueSlot::DoesNotNeedGCBarriers, + AggValueSlot::IsNotAliased); + + CGF.EmitAggExpr(Init, Slot); + } } - + + // Now, outside of the initializer cleanup scope, destroy the backing array + // for a std::initializer_list member. + CGF.MaybeEmitStdInitializerListCleanup(LV, Init); + return; } |