diff options
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstructionCombining.cpp | 9 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SimplifyCFGPass.cpp | 9 |
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 269ea1516f..07793ac6b5 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1169,7 +1169,14 @@ Instruction *InstCombiner::visitMalloc(Instruction &MI) { } if (InvokeInst *II = dyn_cast<InvokeInst>(&MI)) { - BranchInst::Create(II->getNormalDest(), II->getParent()); + // Replace invoke with a NOOP intrinsic to maintain the original CFG + Module *M = II->getParent()->getParent()->getParent(); + IntegerType *Ty = IntegerType::get(II->getContext(), 8); + ConstantInt *CI = ConstantInt::get(Ty, 0); + Value *Args[] = {CI, CI}; + Function *F = Intrinsic::getDeclaration(M, Intrinsic::expect, Ty); + InvokeInst::Create(F, II->getNormalDest(), II->getUnwindDest(), Args, + "dummy", II->getParent()); } return EraseInstFromFunction(MI); } diff --git a/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/lib/Transforms/Scalar/SimplifyCFGPass.cpp index a66b3e3825..594369780a 100644 --- a/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -157,11 +157,16 @@ static bool MarkAliveBlocks(BasicBlock *BB, } // Turn invokes that call 'nounwind' functions into ordinary calls. - if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) - if (II->doesNotThrow()) { + if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) { + Value *Callee = II->getCalledValue(); + if (isa<ConstantPointerNull>(Callee) || isa<UndefValue>(Callee)) { + ChangeToUnreachable(II, true); + Changed = true; + } else if (II->doesNotThrow()) { ChangeToCall(II); Changed = true; } + } Changed |= ConstantFoldTerminator(BB, true); for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) |