[cfe-commits] r72655 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CGExpr.cpp CGExprAgg.cpp CodeGenFunction.h

Anders Carlsson andersca at mac.com
Sat May 30 17:34:10 PDT 2009


Author: andersca
Date: Sat May 30 19:34:10 2009
New Revision: 72655

URL: http://llvm.org/viewvc/llvm-project?rev=72655&view=rev
Log:
Emit destructors correctly for temporaries.

Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sat May 30 19:34:10 2009
@@ -189,14 +189,40 @@
                          E->arg_begin(), E->arg_end());
 }
 
+void CodeGenFunction::PushCXXTemporary(const CXXTemporary *Temporary, 
+                                       llvm::Value *Ptr) {
+  LiveTemporaries.push_back(Temporary);
+  
+  // Make a cleanup scope and emit the destructor.
+  {
+    CleanupScope Scope(*this);
+   
+    EmitCXXDestructorCall(Temporary->getDestructor(), Dtor_Complete, Ptr);
+  }
+}
+
 RValue 
 CodeGenFunction::EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E,
                                             llvm::Value *AggLoc,
                                             bool isAggLocVolatile) {
+  // Keep track of the current cleanup stack depth.
+  size_t CleanupStackDepth = CleanupEntries.size();
+
+  unsigned OldNumLiveTemporaries = LiveTemporaries.size();
+  
   RValue RV = EmitAnyExpr(E->getSubExpr(), AggLoc, isAggLocVolatile);
   
-  // FIXME: Handle the temporaries.
+  // Go through the temporaries backwards.
+  for (unsigned i = E->getNumTemporaries(); i != 0; --i) {
+    assert(LiveTemporaries.back() == E->getTemporary(i - 1));
+    LiveTemporaries.pop_back();
+  }
+
+  assert(OldNumLiveTemporaries == LiveTemporaries.size() &&
+         "Live temporary stack mismatch!");
   
+  EmitCleanupBlocks(CleanupStackDepth);
+
   return RV;
 }
 

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat May 30 19:34:10 2009
@@ -1213,7 +1213,7 @@
 CodeGenFunction::EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E) {
   LValue LV = EmitLValue(E->getSubExpr());
   
-  // FIXME: Record the value and dest ptr.
+  PushCXXTemporary(E->getTemporary(), LV.getAddress());
   
   return LV;
 }

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Sat May 30 19:34:10 2009
@@ -303,7 +303,7 @@
   } else 
     Visit(E->getSubExpr());
   
-  // FIXME: Record the value and dest ptr.
+  CGF.PushCXXTemporary(E->getTemporary(), Val);
 }
 
 void

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat May 30 19:34:10 2009
@@ -239,6 +239,8 @@
   /// 'this' declaration.
   ImplicitParamDecl *CXXThisDecl;
   
+  llvm::SmallVector<const CXXTemporary*, 4> LiveTemporaries;
+  
 public:
   CodeGenFunction(CodeGenModule &cgm);
 
@@ -480,6 +482,8 @@
   void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
                              llvm::Value *This);
   
+  void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr);
+  
   //===--------------------------------------------------------------------===//
   //                            Declaration Emission
   //===--------------------------------------------------------------------===//





More information about the cfe-commits mailing list