[cfe-commits] r95501 - /cfe/trunk/lib/CodeGen/CGClass.cpp

Anders Carlsson andersca at mac.com
Sat Feb 6 11:50:17 PST 2010


Author: andersca
Date: Sat Feb  6 13:50:17 2010
New Revision: 95501

URL: http://llvm.org/viewvc/llvm-project?rev=95501&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=95501&r1=95500&r2=95501&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Sat Feb  6 13:50:17 2010
@@ -849,6 +849,25 @@
   } 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());
+    }
   }
 }
 





More information about the cfe-commits mailing list