diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 47c37c46587..9c420c83873 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -703,8 +703,13 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) { // This allows ValueHandlers and custom metadata to adjust itself. if (!OldCall->getType()->isVoidTy()) OldCall->replaceAllUsesWith(UndefValue::get(OldCall->getType())); - if (isa(OldCall)) // Not worth removing an invoke here. + if (isa(OldCall)) return EraseInstFromFunction(*OldCall); + + // We cannot remove an invoke, because it would change the CFG, just + // change the callee to a null pointer. + cast(OldCall)->setOperand(0, + Constant::getNullValue(CalleeF->getType())); return 0; } diff --git a/test/Transforms/InstCombine/crash.ll b/test/Transforms/InstCombine/crash.ll index 732a8826217..a4e6a62d9e6 100644 --- a/test/Transforms/InstCombine/crash.ll +++ b/test/Transforms/InstCombine/crash.ll @@ -204,3 +204,25 @@ declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind declare void @_ZSt9terminatev() declare void @_Unwind_Resume_or_Rethrow(i8*) + + + +; rdar://7590304 +define i8* @test10(i8* %self, i8* %tmp3) { +entry: + store i1 true, i1* undef + store i1 true, i1* undef + invoke arm_apcscc void @test10a() + to label %invoke.cont unwind label %try.handler ; [#uses=0] + +invoke.cont: ; preds = %entry + unreachable + +try.handler: ; preds = %entry + ret i8* %self +} + +define void @test10a() { + ret void +} +