[cfe-commits] r64051 - in /cfe/trunk/lib/CodeGen: CGStmt.cpp CodeGenFunction.cpp CodeGenFunction.h

Anders Carlsson andersca at mac.com
Sat Feb 7 15:50:39 PST 2009


Author: andersca
Date: Sat Feb  7 17:50:39 2009
New Revision: 64051

URL: http://llvm.org/viewvc/llvm-project?rev=64051&view=rev
Log:
Add support for emitting cleanup blocks. Make EmitCompoundStatement emit cleanup blocks if necessary

Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Feb  7 17:50:39 2009
@@ -123,7 +123,7 @@
 /// (for use by the statement expression extension).
 RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
                                          llvm::Value *AggLoc, bool isAggVol) {
-  // FIXME: handle vla's etc.
+
   CGDebugInfo *DI = CGM.getDebugInfo();
   if (DI) {
     EnsureInsertPoint();
@@ -131,6 +131,9 @@
     DI->EmitRegionStart(CurFn, Builder);
   }
 
+  // Keep track of the current cleanup stack depth.
+  size_t CleanupStackDepth = CleanupEntries.size();
+  
   // Push a null stack save value.
   StackSaveValues.push_back(0);
   
@@ -171,6 +174,8 @@
     Builder.CreateCall(F, V);
   }
   
+  EmitCleanupBlocks(CleanupStackDepth);
+  
   return RV;
 }
 

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sat Feb  7 17:50:39 2009
@@ -521,3 +521,24 @@
   
   return CleanupBlock;  
 }
+
+void CodeGenFunction::EmitCleanupBlocks(size_t OldCleanupStackSize)
+{
+  assert(CleanupEntries.size() >= OldCleanupStackSize && 
+         "Cleanup stack mismatch!");
+  
+  while (CleanupEntries.size() > OldCleanupStackSize)
+    EmitCleanupBlock();
+}
+
+void CodeGenFunction::EmitCleanupBlock()
+{
+  CleanupEntry &CE = CleanupEntries.back();
+  
+  llvm::BasicBlock *CleanupBlock = CE.CleanupBlock;
+  
+  CleanupEntries.pop_back();
+  
+  EmitBlock(CleanupBlock);
+}
+

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Feb  7 17:50:39 2009
@@ -151,6 +151,10 @@
     }
   };
 
+  /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
+  /// blocks that have been added.
+  void EmitCleanupBlocks(size_t OldCleanupStackSize);
+
 private:
   /// LabelIDs - Track arbitrary ids assigned to labels for use in
   /// implementing the GCC address-of-label extension and indirect
@@ -762,6 +766,9 @@
   llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info,
                             const Expr *InputExpr, std::string &ConstraintStr);
   
+  /// EmitCleanupBlock - emits a single cleanup block.
+  void EmitCleanupBlock();
+
 };
 }  // end namespace CodeGen
 }  // end namespace clang





More information about the cfe-commits mailing list