Misc fixes to the cleanup stack code.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64096 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index b62499d..4ae8708 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -586,7 +586,11 @@
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::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;