[cfe-commits] r83397 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGenCXX/destructor-calls.cpp

Anders Carlsson andersca at mac.com
Tue Oct 6 11:09:57 PDT 2009


Author: andersca
Date: Tue Oct  6 13:09:57 2009
New Revision: 83397

URL: http://llvm.org/viewvc/llvm-project?rev=83397&view=rev
Log:
Emit the destructor epilogue in a cleanup block so a return from a destructor body still calls the epilogue.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGenCXX/destructor-calls.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Oct  6 13:09:57 2009
@@ -233,11 +233,30 @@
   // FIXME: Support CXXTryStmt here, too.
   if (const CompoundStmt *S = FD->getCompoundBody()) {
     StartFunction(GD, FD->getResultType(), Fn, Args, S->getLBracLoc());
+    const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(FD);
+    llvm::BasicBlock *DtorEpilogue = 0;
+    if (DD) {
+      DtorEpilogue = createBasicBlock("dtor.epilogue");
+    
+      PushCleanupBlock(DtorEpilogue);
+    }
+    
     if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD))
       EmitCtorPrologue(CD, GD.getCtorType());
     EmitStmt(S);
-    if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(FD))
+      
+    if (DD) {
+      CleanupBlockInfo Info = PopCleanupBlock();
+
+      assert(Info.CleanupBlock == DtorEpilogue && "Block mismatch!");
+      EmitBlock(DtorEpilogue);
       EmitDtorEpilogue(DD, GD.getDtorType());
+      
+      if (Info.SwitchBlock)
+        EmitBlock(Info.SwitchBlock);
+      if (Info.EndBlock)
+        EmitBlock(Info.EndBlock);
+    }
     FinishFunction(S->getRBracLoc());
   } else if (FD->isImplicit()) {
     const CXXRecordDecl *ClassDecl =

Modified: cfe/trunk/test/CodeGenCXX/destructor-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructor-calls.cpp?rev=83397&r1=83396&r2=83397&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructor-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/destructor-calls.cpp Tue Oct  6 13:09:57 2009
@@ -30,7 +30,12 @@
   P p;
 };
 
+struct O : B { 
+  ~O() { return; } 
+};
+
 int main() {
   N n1;
   N n2;
+  O o;
 }





More information about the cfe-commits mailing list