Do not crash when dealing with invoke and unwind instructions!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10160 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2003-11-22 02:10:38 +00:00
parent 89eca9097d
commit 8bc098be0c

View File

@ -195,20 +195,23 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<BasicBlock*> &BBs) {
// Loop over and delete any hack up any blocks that are not listed... // Loop over and delete any hack up any blocks that are not listed...
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB) for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB)
if (!Blocks.count(BB) && !isa<ReturnInst>(BB->getTerminator())) { if (!Blocks.count(BB) && BB->getTerminator()->getNumSuccessors()) {
// Loop over all of the successors of this block, deleting any PHI nodes // Loop over all of the successors of this block, deleting any PHI nodes
// that might include it. // that might include it.
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
(*SI)->removePredecessor(BB); (*SI)->removePredecessor(BB);
if (BB->getTerminator()->getType() != Type::VoidTy)
BB->getTerminator()->replaceAllUsesWith(
Constant::getNullValue(BB->getTerminator()->getType()));
// Delete the old terminator instruction... // Delete the old terminator instruction...
BB->getInstList().pop_back(); BB->getInstList().pop_back();
// Add a new return instruction of the appropriate type... // Add a new return instruction of the appropriate type...
const Type *RetTy = BB->getParent()->getReturnType(); const Type *RetTy = BB->getParent()->getReturnType();
ReturnInst *RI = new ReturnInst(RetTy == Type::VoidTy ? 0 : new ReturnInst(RetTy == Type::VoidTy ? 0 :
Constant::getNullValue(RetTy)); Constant::getNullValue(RetTy), BB);
BB->getInstList().push_back(RI);
} }
// The CFG Simplifier pass may delete one of the basic blocks we are // The CFG Simplifier pass may delete one of the basic blocks we are