aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGClass.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-02-06 19:50:17 +0000
committerAnders Carlsson <andersca@mac.com>2010-02-06 19:50:17 +0000
commit9405dcd83f090d86d5d06ab3a4e59cc39e7edd93 (patch)
treea05f80de04cb70a5d8811f58f66099aa2aefb294 /lib/CodeGen/CGClass.cpp
parent645cf44cc34371c808743e5e7c19bb41ff593ca0 (diff)
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95501 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGClass.cpp')
-rw-r--r--lib/CodeGen/CGClass.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp
index 3804a7cf83..4ec524da8b 100644
--- a/lib/CodeGen/CGClass.cpp
+++ b/lib/CodeGen/CGClass.cpp
@@ -849,6 +849,25 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
} else {
CGF.EmitAggExpr(MemberInit->getInit(), LHS.getAddress(),
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());
+ }
}
}