From 0efa921736fefde26003aca8d182ab7eb722394b Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Wed, 29 Jul 2009 05:17:50 +0000 Subject: 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 --- lib/Transforms/Scalar/SimplifyLibCalls.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/Transforms/Scalar/SimplifyLibCalls.cpp') 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; } }; -- cgit v1.1