Block Code Gen. API. Call destructor on descriptior

entry previously constructed via copy constructor.

llvm-svn: 105641
This commit is contained in:
Fariborz Jahanian 2010-06-08 20:57:22 +00:00
parent d04e1a7ef1
commit 3b83618054
2 changed files with 33 additions and 3 deletions

View File

@ -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(),

View File

@ -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