From: Fariborz Jahanian Date: Tue, 8 Jun 2010 20:57:22 +0000 (+0000) Subject: Block Code Gen. API. Call destructor on descriptior X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac7362dedab6002a0811f47ccfcaf81a9c728d35;p=clang Block Code Gen. API. Call destructor on descriptior entry previously constructed via copy constructor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105641 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index b2d7f2e81d..f07b7bbbda 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -361,8 +361,36 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) { Builder.CreateStore(Loc, Addr); continue; } else { - if (BDRE->getCopyConstructorExpr()) - E = BDRE->getCopyConstructorExpr(); + if (BDRE->getCopyConstructorExpr()) { + E = BDRE->getCopyConstructorExpr(); + // Code to destruct copy-constructed descriptor element for + // copied-in class object. + // TODO: Refactor this into common code with mostly similar + // CodeGenFunction::EmitLocalBlockVarDecl + QualType DtorTy = E->getType(); + if (const RecordType *RT = DtorTy->getAs()) + if (CXXRecordDecl *ClassDecl = + dyn_cast(RT->getDecl())) { + if (!ClassDecl->hasTrivialDestructor()) { + const CXXDestructorDecl *D = + ClassDecl->getDestructor(getContext()); + assert(D && "BuildBlockLiteralTmp - destructor is nul"); + { + // Normal destruction. + DelayedCleanupBlock Scope(*this); + EmitCXXDestructorCall(D, Dtor_Complete, + /*ForVirtualBase=*/false, Addr); + // Make sure to jump to the exit block. + EmitBranch(Scope.getCleanupExitBlock()); + } + if (Exceptions) { + EHCleanupBlock Cleanup(*this); + EmitCXXDestructorCall(D, Dtor_Complete, + /*ForVirtualBase=*/false, Addr); + } + } + } + } else { E = new (getContext()) DeclRefExpr(const_cast(VD), VD->getType().getNonReferenceType(), diff --git a/test/CodeGenCXX/copy-in-cplus-object.cpp b/test/CodeGenCXX/copy-in-cplus-object.cpp index cac6155f5c..bdfca5e4ee 100644 --- a/test/CodeGenCXX/copy-in-cplus-object.cpp +++ b/test/CodeGenCXX/copy-in-cplus-object.cpp @@ -9,6 +9,7 @@ struct TestObject { TestObject(const TestObject& inObj, int def = 100, const S &Silly = "silly"); TestObject(); + ~TestObject(); TestObject& operator=(const TestObject& inObj); int version() const; @@ -23,4 +24,5 @@ void testRoutine() { // CHECK: call void @_ZN1SC1EPKc // CHECK: call void @_ZN10TestObjectC1ERKS_iRK1S // CHECK: call void @_ZN1SD1Ev - +// CHECK: call void @_ZN10TestObjectD1Ev +// CHECK: call void @_ZN10TestObjectD1Ev