aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-07-29 05:17:50 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-07-29 05:17:50 +0000
commit0efa921736fefde26003aca8d182ab7eb722394b (patch)
tree9a608794f0c65e7d809ae6c088535f7994dc9793 /lib/Transforms/Scalar/SimplifyLibCalls.cpp
parente53a600f065075731d0aeb9dc8f4f3d75f5a05f8 (diff)
downloadexternal_llvm-0efa921736fefde26003aca8d182ab7eb722394b.zip
external_llvm-0efa921736fefde26003aca8d182ab7eb722394b.tar.gz
external_llvm-0efa921736fefde26003aca8d182ab7eb722394b.tar.bz2
Bulk erasing instructions without RAUWing them is unsafe. Instead, break them
into a new BB that has no predecessors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77433 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SimplifyLibCalls.cpp')
-rw-r--r--lib/Transforms/Scalar/SimplifyLibCalls.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index 506ba1f..14212bc 100644
--- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
@@ -519,17 +519,19 @@ struct VISIBILITY_HIDDEN ExitOpt : public LibCallOptimization {
TerminatorInst *OldTI = CI->getParent()->getTerminator();
- // Create the return after the call.
- ReturnInst *RI = B.CreateRet(CI->getOperand(1));
-
// Drop all successor phi node entries.
for (unsigned i = 0, e = OldTI->getNumSuccessors(); i != e; ++i)
OldTI->getSuccessor(i)->removePredecessor(CI->getParent());
- // Erase all instructions from after our return instruction until the end of
- // the block.
- BasicBlock::iterator FirstDead = RI; ++FirstDead;
- CI->getParent()->getInstList().erase(FirstDead, CI->getParent()->end());
+ // Split the basic block after the call to exit.
+ BasicBlock::iterator FirstDead = CI; ++FirstDead;
+ CI->getParent()->splitBasicBlock(FirstDead);
+ B.SetInsertPoint(B.GetInsertBlock());
+
+ // Remove the branch that splitBB created and insert a return instead.
+ CI->getParent()->getTerminator()->eraseFromParent();
+ B.CreateRet(CI->getOperand(1));
+
return CI;
}
};