diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index c2f55d896ba..22a95fa03f7 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -252,7 +252,8 @@ void PruneEH::DeleteBasicBlock(BasicBlock *BB) { } if (TokenInst) { - changeToUnreachable(TokenInst->getNextNode(), /*UseLLVMTrap=*/false); + if (!isa(TokenInst)) + changeToUnreachable(TokenInst->getNextNode(), /*UseLLVMTrap=*/false); } else { // Get the list of successors of this block. std::vector Succs(succ_begin(BB), succ_end(BB)); diff --git a/test/Transforms/PruneEH/pr26263.ll b/test/Transforms/PruneEH/pr26263.ll index 3670f00d811..17fafeb6850 100644 --- a/test/Transforms/PruneEH/pr26263.ll +++ b/test/Transforms/PruneEH/pr26263.ll @@ -27,4 +27,30 @@ cleanupret: ; CHECK: cleanupret from %[[cp]] unwind to caller +define void @test2() personality i32 (...)* @__CxxFrameHandler3 { + invoke void @neverthrows() + to label %try.cont unwind label %catchswitch + +try.cont: + ret void + +catchswitch: + %cs = catchswitch within none [label %catchpad] unwind to caller + +catchpad: + %cp = catchpad within %cs [] + unreachable + +ret: + ret void +} + +; CHECK-LABEL: define void @test2( +; CHECK: call void @neverthrows() + +; CHECK: %[[cs:.*]] = catchswitch within none [label + +; CHECK: catchpad within %[[cs]] [] +; CHECK-NEXT: unreachable + declare i32 @__CxxFrameHandler3(...)