[cfe-commits] r108978 - in /cfe/trunk: lib/CodeGen/CGClass.cpp test/CodeGenCXX/destructors.cpp

John McCall rjmccall at apple.com
Tue Jul 20 18:23:41 PDT 2010


Author: rjmccall
Date: Tue Jul 20 20:23:41 2010
New Revision: 108978

URL: http://llvm.org/viewvc/llvm-project?rev=108978&view=rev
Log:
Convert the EH cleanups for base and member destructors in a constructor into
lazy cleanups.


Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/test/CodeGenCXX/destructors.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=108978&r1=108977&r2=108978&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Jul 20 20:23:41 2010
@@ -310,6 +310,22 @@
   return VTT;
 }
 
+namespace {
+  struct CallBaseDtor : EHScopeStack::LazyCleanup {
+    CXXDestructorDecl *Dtor;
+    bool isBaseVirtual;
+    llvm::Value *Addr;
+
+    CallBaseDtor(CXXDestructorDecl *DD, bool isVirtual, llvm::Value *Addr)
+      : Dtor(DD), isBaseVirtual(isVirtual), Addr(Addr) {}
+
+    void Emit(CodeGenFunction &CGF, bool IsForEH) {
+      // FIXME: Is this OK for C++0x delegating constructors?
+      CGF.EmitCXXDestructorCall(Dtor, Dtor_Base, isBaseVirtual, Addr);
+    }
+  };
+}
+
 static void EmitBaseInitializer(CodeGenFunction &CGF, 
                                 const CXXRecordDecl *ClassDecl,
                                 CXXBaseOrMemberInitializer *BaseInit,
@@ -338,13 +354,10 @@
 
   CGF.EmitAggExpr(BaseInit->getInit(), V, false, false, true);
   
-  if (CGF.Exceptions && !BaseClassDecl->hasTrivialDestructor()) {
-    // FIXME: Is this OK for C++0x delegating constructors?
-    CodeGenFunction::CleanupBlock Cleanup(CGF, EHCleanup);
-
-    CXXDestructorDecl *DD = BaseClassDecl->getDestructor();
-    CGF.EmitCXXDestructorCall(DD, Dtor_Base, isBaseVirtual, V);
-  }
+  if (CGF.Exceptions && !BaseClassDecl->hasTrivialDestructor())
+    CGF.EHStack.pushLazyCleanup<CallBaseDtor>(EHCleanup,
+                                              BaseClassDecl->getDestructor(),
+                                              isBaseVirtual, V);
 }
 
 static void EmitAggMemberInitializer(CodeGenFunction &CGF,
@@ -432,6 +445,25 @@
   // Emit the fall-through block.
   CGF.EmitBlock(AfterFor, true);
 }
+
+namespace {
+  struct CallMemberDtor : EHScopeStack::LazyCleanup {
+    FieldDecl *Field;
+    CXXDestructorDecl *Dtor;
+
+    CallMemberDtor(FieldDecl *Field, CXXDestructorDecl *Dtor)
+      : Field(Field), Dtor(Dtor) {}
+
+    void Emit(CodeGenFunction &CGF, bool IsForEH) {
+      // FIXME: Is this OK for C++0x delegating constructors?
+      llvm::Value *ThisPtr = CGF.LoadCXXThis();
+      LValue LHS = CGF.EmitLValueForField(ThisPtr, Field, 0);
+
+      CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete, /*ForVirtualBase=*/false,
+                                LHS.getAddress());
+    }
+  };
+}
   
 static void EmitMemberInitializer(CodeGenFunction &CGF,
                                   const CXXRecordDecl *ClassDecl,
@@ -532,17 +564,9 @@
       return;
     
     CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
-    if (!RD->hasTrivialDestructor()) {
-      // FIXME: Is this OK for C++0x delegating constructors?
-      CodeGenFunction::CleanupBlock Cleanup(CGF, EHCleanup);
-      
-      llvm::Value *ThisPtr = CGF.LoadCXXThis();
-      LValue LHS = CGF.EmitLValueForField(ThisPtr, Field, 0);
-
-      CXXDestructorDecl *DD = RD->getDestructor();
-      CGF.EmitCXXDestructorCall(DD, Dtor_Complete, /*ForVirtualBase=*/false,
-                                LHS.getAddress());
-    }
+    if (!RD->hasTrivialDestructor())
+      CGF.EHStack.pushLazyCleanup<CallMemberDtor>(EHCleanup, Field,
+                                                  RD->getDestructor());
   }
 }
 

Modified: cfe/trunk/test/CodeGenCXX/destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=108978&r1=108977&r2=108978&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Tue Jul 20 20:23:41 2010
@@ -262,11 +262,6 @@
 
 // Checks from test3:
 
-  // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev(
-  // CHECK: call void @_ZN5test31BD2Ev(
-  // CHECK: call void @_ZN5test31AD2Ev(
-  // CHECK: ret void
-
   // CHECK: define internal void @_ZN5test312_GLOBAL__N_11DD0Ev(
   // CHECK: invoke void @_ZN5test312_GLOBAL__N_11DD1Ev(
   // CHECK: call void @_ZdlPv({{.*}}) nounwind
@@ -289,6 +284,11 @@
   // CHECK: call void @_ZN5test312_GLOBAL__N_11DD0Ev(
   // CHECK: ret void
 
+  // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev(
+  // CHECK: call void @_ZN5test31BD2Ev(
+  // CHECK: call void @_ZN5test31AD2Ev(
+  // CHECK: ret void
+
   // CHECK: declare void @_ZN5test31BD2Ev(
   // CHECK: declare void @_ZN5test31AD2Ev(
 





More information about the cfe-commits mailing list