From f62478a34a38b129041f43766bbf5525c4914e18 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 23 Jan 2016 06:00:44 +0000 Subject: [PATCH] [PruneEH] Don't try to insert a terminator after another terminator LLVM's BasicBlock has a single terminator, it is not valid to have two. llvm-svn: 258616 --- lib/Transforms/IPO/PruneEH.cpp | 3 ++- test/Transforms/PruneEH/pr26263.ll | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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(...)