diff options
-rw-r--r-- | lib/CodeGen/CGClass.cpp | 50 | ||||
-rw-r--r-- | lib/CodeGen/CGExprCXX.cpp | 39 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 3 |
3 files changed, 29 insertions, 63 deletions
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index fbbf9a554d..38fdb344ff 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -534,10 +534,6 @@ static bool hasTrivialCopyOrMoveConstructor(const CXXRecordDecl *Record, Record->hasTrivialCopyConstructor(); } -static void EmitInitializerForField(CodeGenFunction &CGF, FieldDecl *Field, - LValue LHS, Expr *Init, - ArrayRef<VarDecl *> ArrayIndexes); - static void EmitMemberInitializer(CodeGenFunction &CGF, const CXXRecordDecl *ClassDecl, CXXCtorInitializer *MemberInit, @@ -594,54 +590,52 @@ static void EmitMemberInitializer(CodeGenFunction &CGF, ArrayRef<VarDecl *> ArrayIndexes; if (MemberInit->getNumArrayIndices()) ArrayIndexes = MemberInit->getArrayIndexes(); - EmitInitializerForField(CGF, Field, LHS, MemberInit->getInit(), ArrayIndexes); + CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit(), ArrayIndexes); } -static void EmitInitializerForField(CodeGenFunction &CGF, FieldDecl *Field, - LValue LHS, Expr *Init, - ArrayRef<VarDecl *> ArrayIndexes) { +void CodeGenFunction::EmitInitializerForField(FieldDecl *Field, + LValue LHS, Expr *Init, + ArrayRef<VarDecl *> ArrayIndexes) { QualType FieldType = Field->getType(); - if (!CGF.hasAggregateLLVMType(FieldType)) { + if (!hasAggregateLLVMType(FieldType)) { if (LHS.isSimple()) { - CGF.EmitExprAsInit(Init, Field, LHS, false); + EmitExprAsInit(Init, Field, LHS, false); } else { - RValue RHS = RValue::get(CGF.EmitScalarExpr(Init)); - CGF.EmitStoreThroughLValue(RHS, LHS); + RValue RHS = RValue::get(EmitScalarExpr(Init)); + EmitStoreThroughLValue(RHS, LHS); } } else if (FieldType->isAnyComplexType()) { - CGF.EmitComplexExprIntoAddr(Init, LHS.getAddress(), - LHS.isVolatileQualified()); + EmitComplexExprIntoAddr(Init, LHS.getAddress(), LHS.isVolatileQualified()); } else { llvm::Value *ArrayIndexVar = 0; if (ArrayIndexes.size()) { - llvm::Type *SizeTy - = CGF.ConvertType(CGF.getContext().getSizeType()); + llvm::Type *SizeTy = ConvertType(getContext().getSizeType()); // The LHS is a pointer to the first object we'll be constructing, as // a flat array. - QualType BaseElementTy = CGF.getContext().getBaseElementType(FieldType); - llvm::Type *BasePtr = CGF.ConvertType(BaseElementTy); + QualType BaseElementTy = getContext().getBaseElementType(FieldType); + llvm::Type *BasePtr = ConvertType(BaseElementTy); BasePtr = llvm::PointerType::getUnqual(BasePtr); - llvm::Value *BaseAddrPtr = CGF.Builder.CreateBitCast(LHS.getAddress(), - BasePtr); - LHS = CGF.MakeAddrLValue(BaseAddrPtr, BaseElementTy); + llvm::Value *BaseAddrPtr = Builder.CreateBitCast(LHS.getAddress(), + BasePtr); + LHS = MakeAddrLValue(BaseAddrPtr, BaseElementTy); // Create an array index that will be used to walk over all of the // objects we're constructing. - ArrayIndexVar = CGF.CreateTempAlloca(SizeTy, "object.index"); + ArrayIndexVar = CreateTempAlloca(SizeTy, "object.index"); llvm::Value *Zero = llvm::Constant::getNullValue(SizeTy); - CGF.Builder.CreateStore(Zero, ArrayIndexVar); + Builder.CreateStore(Zero, ArrayIndexVar); // Emit the block variables for the array indices, if any. for (unsigned I = 0, N = ArrayIndexes.size(); I != N; ++I) - CGF.EmitAutoVarDecl(*ArrayIndexes[I]); + EmitAutoVarDecl(*ArrayIndexes[I]); } - EmitAggMemberInitializer(CGF, LHS, Init, ArrayIndexVar, FieldType, + EmitAggMemberInitializer(*this, LHS, Init, ArrayIndexVar, FieldType, ArrayIndexes, 0); - if (!CGF.CGM.getLangOptions().Exceptions) + if (!CGM.getLangOptions().Exceptions) return; // FIXME: If we have an array of classes w/ non-trivial destructors, @@ -653,8 +647,8 @@ static void EmitInitializerForField(CodeGenFunction &CGF, FieldDecl *Field, CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); if (!RD->hasTrivialDestructor()) - CGF.EHStack.pushCleanup<CallMemberDtor>(EHCleanup, LHS.getAddress(), - RD->getDestructor()); + EHStack.pushCleanup<CallMemberDtor>(EHCleanup, LHS.getAddress(), + RD->getDestructor()); } } diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 673c9442e0..7b1ae1cc24 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -1765,24 +1765,6 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(llvm::Value *Value, return Value; } -namespace { - struct CallLambdaMemberDtor : EHScopeStack::Cleanup { - FieldDecl *Field; - CXXDestructorDecl *Dtor; - llvm::Value *Lambda; - - CallLambdaMemberDtor(FieldDecl *Field, CXXDestructorDecl *Dtor, - llvm::Value *Lambda) - : Field(Field), Dtor(Dtor), Lambda(Lambda) {} - - void Emit(CodeGenFunction &CGF, Flags flags) { - LValue LHS = CGF.EmitLValueForField(Lambda, Field, 0); - CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete, /*ForVirtualBase=*/false, - LHS.getAddress()); - } - }; -} - void CodeGenFunction::EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Slot) { RunCleanupsScope Scope(*this); @@ -1790,24 +1772,11 @@ void CodeGenFunction::EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Slot) { for (LambdaExpr::capture_init_iterator i = E->capture_init_begin(), e = E->capture_init_end(); i != e; ++i, ++CurField) { - // FIXME: Add array handling - // FIXME: Try to refactor with CodeGenFunction::EmitCtorPrologue - // Emit initialization LValue LV = EmitLValueForFieldInitialization(Slot.getAddr(), *CurField, 0); - EmitExprAsInit(*i, *CurField, LV, false); - - // Add temporary cleanup to handle the case where a later initialization - // throws. - if (!CGM.getLangOptions().Exceptions) - continue; - const RecordType *RT = CurField->getType()->getAs<RecordType>(); - if (!RT) - continue; - CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); - if (!RD->hasTrivialDestructor()) - EHStack.pushCleanup<CallLambdaMemberDtor>(EHCleanup, *CurField, - RD->getDestructor(), - Slot.getAddr()); + ArrayRef<VarDecl *> ArrayIndexes; + if (CurField->getType()->isArrayType()) + ArrayIndexes = E->getCaptureInitIndexVars(i); + EmitInitializerForField(*CurField, LV, *i, ArrayIndexes); } } diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index ca5b88363e..9081ece6f8 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1394,6 +1394,9 @@ public: void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, FunctionArgList &Args); + void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init, + ArrayRef<VarDecl *> ArrayIndexes); + /// InitializeVTablePointer - Initialize the vtable pointer of the given /// subobject. /// |