Skip to content

Commit 3b83618

Browse files
author
Fariborz Jahanian
committed
Block Code Gen. API. Call destructor on descriptior
entry previously constructed via copy constructor. llvm-svn: 105641
1 parent d04e1a7 commit 3b83618

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,36 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
361361
Builder.CreateStore(Loc, Addr);
362362
continue;
363363
} else {
364-
if (BDRE->getCopyConstructorExpr())
365-
E = BDRE->getCopyConstructorExpr();
364+
if (BDRE->getCopyConstructorExpr()) {
365+
E = BDRE->getCopyConstructorExpr();
366+
// Code to destruct copy-constructed descriptor element for
367+
// copied-in class object.
368+
// TODO: Refactor this into common code with mostly similar
369+
// CodeGenFunction::EmitLocalBlockVarDecl
370+
QualType DtorTy = E->getType();
371+
if (const RecordType *RT = DtorTy->getAs<RecordType>())
372+
if (CXXRecordDecl *ClassDecl =
373+
dyn_cast<CXXRecordDecl>(RT->getDecl())) {
374+
if (!ClassDecl->hasTrivialDestructor()) {
375+
const CXXDestructorDecl *D =
376+
ClassDecl->getDestructor(getContext());
377+
assert(D && "BuildBlockLiteralTmp - destructor is nul");
378+
{
379+
// Normal destruction.
380+
DelayedCleanupBlock Scope(*this);
381+
EmitCXXDestructorCall(D, Dtor_Complete,
382+
/*ForVirtualBase=*/false, Addr);
383+
// Make sure to jump to the exit block.
384+
EmitBranch(Scope.getCleanupExitBlock());
385+
}
386+
if (Exceptions) {
387+
EHCleanupBlock Cleanup(*this);
388+
EmitCXXDestructorCall(D, Dtor_Complete,
389+
/*ForVirtualBase=*/false, Addr);
390+
}
391+
}
392+
}
393+
}
366394
else {
367395
E = new (getContext()) DeclRefExpr(const_cast<ValueDecl*>(VD),
368396
VD->getType().getNonReferenceType(),

clang/test/CodeGenCXX/copy-in-cplus-object.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct TestObject
99
{
1010
TestObject(const TestObject& inObj, int def = 100, const S &Silly = "silly");
1111
TestObject();
12+
~TestObject();
1213
TestObject& operator=(const TestObject& inObj);
1314
int version() const;
1415

@@ -23,4 +24,5 @@ void testRoutine() {
2324
// CHECK: call void @_ZN1SC1EPKc
2425
// CHECK: call void @_ZN10TestObjectC1ERKS_iRK1S
2526
// CHECK: call void @_ZN1SD1Ev
26-
27+
// CHECK: call void @_ZN10TestObjectD1Ev
28+
// CHECK: call void @_ZN10TestObjectD1Ev

0 commit comments

Comments
 (0)