]> granicus.if.org Git - clang/commitdiff
Add support for emitting cleanup blocks. Make EmitCompoundStatement emit cleanup...
authorAnders Carlsson <andersca@mac.com>
Sat, 7 Feb 2009 23:50:39 +0000 (23:50 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 7 Feb 2009 23:50:39 +0000 (23:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64051 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGStmt.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h

index ac97c6329dab1f282382cd5585de9a0a2dd3f13f..fc7a7c7f8f1e4d38aa1b6e7ddf043e484cd5e0bd 100644 (file)
@@ -123,7 +123,7 @@ bool CodeGenFunction::EmitSimpleStmt(const Stmt *S) {
 /// (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 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
     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 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
     Builder.CreateCall(F, V);
   }
   
+  EmitCleanupBlocks(CleanupStackDepth);
+  
   return RV;
 }
 
index 4ba4d600f864693a3659845641f3364648640820..838de70218d5941da70d805ed3470ad4a936c149 100644 (file)
@@ -521,3 +521,24 @@ llvm::BasicBlock *CodeGenFunction::CreateCleanupBlock()
   
   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);
+}
+
index 1f037600f51f77f9763946f9e1fb766f9d2d288c..8a0220724e5df2681c79caaf66fa507840c2c7c9 100644 (file)
@@ -151,6 +151,10 @@ public:
     }
   };
 
+  /// 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 @@ private:
   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