If a constructor throws an exception we need to execute the destructors for all fully constructed members. Fixes ctor_dtor_count.cpp in the test suite.

llvm-svn: 95501
This commit is contained in:
Anders Carlsson 2010-02-06 19:50:17 +00:00
parent d6fff557db
commit ba63167b64
1 changed files with 19 additions and 0 deletions

View File

@ -849,6 +849,25 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
} else { } else {
CGF.EmitAggExpr(MemberInit->getInit(), LHS.getAddress(), CGF.EmitAggExpr(MemberInit->getInit(), LHS.getAddress(),
LHS.isVolatileQualified(), false, true); LHS.isVolatileQualified(), false, true);
if (!CGF.Exceptions)
return;
const RecordType *RT = FieldType->getAs<RecordType>();
if (!RT)
return;
CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
if (!RD->hasTrivialDestructor()) {
// FIXME: Is this OK for C++0x delegating constructors?
CodeGenFunction::EHCleanupBlock Cleanup(CGF);
llvm::Value *ThisPtr = CGF.LoadCXXThis();
LValue LHS = CGF.EmitLValueForField(ThisPtr, Field, 0);
CXXDestructorDecl *DD = RD->getDestructor(CGF.getContext());
CGF.EmitCXXDestructorCall(DD, Dtor_Complete, LHS.getAddress());
}
} }
} }