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 | ac7362dedab6002a0811f47ccfcaf81a9c728d35 (patch) | |
tree | 319c9d4a9684314c764f7c13448e9ac68d7171c9 /lib/CodeGen/CGBlocks.cpp | |
parent | c9f362d73b7e76e7cfa800fd6ed8b7f2a84d2f95 (diff) |
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
Diffstat (limited to 'lib/CodeGen/CGBlocks.cpp')
-rw-r--r-- | lib/CodeGen/CGBlocks.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
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<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(), |