diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-08 20:57:22 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-08 20:57:22 +0000 |
commit | 3b836180546c2af22fe55c332e8245d8e1a8b8fb (patch) | |
tree | 6a9c02e25215494dd0685056033f3da20ae7cd2b /clang | |
parent | d04e1a7ef1f18629518a156367a701216e6916f6 (diff) | |
download | bcm5719-llvm-3b836180546c2af22fe55c332e8245d8e1a8b8fb.tar.gz bcm5719-llvm-3b836180546c2af22fe55c332e8245d8e1a8b8fb.zip |
Block Code Gen. API. Call destructor on descriptior
entry previously constructed via copy constructor.
llvm-svn: 105641
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGBlocks.cpp | 32 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/copy-in-cplus-object.cpp | 4 |
2 files changed, 33 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index b2d7f2e81d4..f07b7bbbda9 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/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<RecordType>()) + if (CXXRecordDecl *ClassDecl = + dyn_cast<CXXRecordDecl>(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<ValueDecl*>(VD), VD->getType().getNonReferenceType(), diff --git a/clang/test/CodeGenCXX/copy-in-cplus-object.cpp b/clang/test/CodeGenCXX/copy-in-cplus-object.cpp index cac6155f5cf..bdfca5e4ee0 100644 --- a/clang/test/CodeGenCXX/copy-in-cplus-object.cpp +++ b/clang/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 |