]> granicus.if.org Git - clang/commitdiff
Misc fixes to the cleanup stack code.
authorAnders Carlsson <andersca@mac.com>
Sun, 8 Feb 2009 22:13:37 +0000 (22:13 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 8 Feb 2009 22:13:37 +0000 (22:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64096 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp

index b62499d3adb30116d2c3df404510dbf4afedf5e3..4ae87080546089c7b4a15dcee42e4dc8ec3bf74f 100644 (file)
@@ -586,7 +586,11 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
     llvm::SwitchInst *SI = Builder.CreateSwitch(DestCode, EndBlock, 
                                                 BranchFixups.size());
 
-    Builder.SetInsertPoint(CurBB);
+    // Restore the current basic block (if any)
+    if (CurBB)
+      Builder.SetInsertPoint(CurBB);
+    else
+      Builder.ClearInsertionPoint();
 
     for (size_t i = 0, e = BranchFixups.size(); i != e; ++i) {
       llvm::BranchInst *BI = BranchFixups[i];
@@ -658,8 +662,13 @@ void CodeGenFunction::AddBranchFixup(llvm::BranchInst *BI)
 
 void CodeGenFunction::EmitBranchThroughCleanup(llvm::BasicBlock *Dest)
 {
+  if (!HaveInsertPoint())
+    return;
+  
   llvm::BranchInst* BI = Builder.CreateBr(Dest);
   
+  Builder.ClearInsertionPoint();
+  
   // The stack is empty, no need to do any cleanup.
   if (CleanupEntries.empty())
     return;