]> granicus.if.org Git - clang/commitdiff
When emitting blocks, keep track of which cleanup scope they have. Minor fixes and...
authorAnders Carlsson <andersca@mac.com>
Sun, 8 Feb 2009 00:16:35 +0000 (00:16 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 8 Feb 2009 00:16:35 +0000 (00:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64053 91177308-0d34-0410-b5e6-96231b3b80d8

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

index fc7a7c7f8f1e4d38aa1b6e7ddf043e484cd5e0bd..19977ec380e52a26ae1db4ed45f8907c10bc9e82 100644 (file)
@@ -188,6 +188,12 @@ void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool IsFinished) {
     return;
   }
 
+  // If necessary, associate the block with the cleanup stack size.
+  if (!CleanupEntries.empty()) {
+    BlockScopes[BB] = CleanupEntries.size() - 1;
+    CleanupEntries.back().Blocks.push_back(BB);
+  }
+  
   CurFn->getBasicBlockList().push_back(BB);
   Builder.SetInsertPoint(BB);
 }
index 838de70218d5941da70d805ed3470ad4a936c149..0e0140c9ad77284760f68b2bd38abc4ceacbd237 100644 (file)
@@ -119,7 +119,11 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
 
   assert(BreakContinueStack.empty() &&
          "mismatched push/pop in break/continue stack!");
-
+  assert(BlockScopes.empty() &&
+         "did not remove all blocks from block scope map!");
+  assert(CleanupEntries.empty() &&
+         "mismatched push/pop in cleanup stack!");
+  
   // Emit function epilog (to return). 
   EmitReturnBlock();
 
@@ -537,8 +541,22 @@ void CodeGenFunction::EmitCleanupBlock()
   
   llvm::BasicBlock *CleanupBlock = CE.CleanupBlock;
   
+  std::vector<llvm::BasicBlock *> Blocks;
+  std::swap(Blocks, CE.Blocks);
+
+  std::vector<llvm::BranchInst *> BranchFixups;
+  std::swap(BranchFixups, CE.BranchFixups);
+  
   CleanupEntries.pop_back();
   
   EmitBlock(CleanupBlock);
+  
+  // Remove all blocks from the block scope map.
+  for (size_t i = 0, e = Blocks.size(); i != e; ++i) {
+    assert(BlockScopes.count(Blocks[i]) &&
+           "Did not find block in scope map!");
+    
+    BlockScopes.erase(Blocks[i]);
+  }
 }
 
index 8a0220724e5df2681c79caaf66fa507840c2c7c9..3dbc2c99e7166a6d94ea019fd8433a91e6ba77f1 100644 (file)
@@ -253,11 +253,22 @@ private:
 
     explicit CleanupEntry(llvm::BasicBlock *cb)
       : CleanupBlock(cb) {}
+    
+    ~CleanupEntry() {
+      assert(Blocks.empty() && "Did not empty blocks!");
+      assert(BranchFixups.empty() && "Did not empty branch fixups!");
+    }
+    
   };
   
   /// CleanupEntries - Stack of cleanup entries.
   llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
 
+  typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
+
+  /// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
+  BlockScopeMap BlockScopes;
+  
 public:
   CodeGenFunction(CodeGenModule &cgm);