Merging r258616:
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 17 Feb 2016 18:49:28 +0000 (18:49 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 17 Feb 2016 18:49:28 +0000 (18:49 +0000)
------------------------------------------------------------------------
r258616 | majnemer | 2016-01-22 22:00:44 -0800 (Fri, 22 Jan 2016) | 3 lines

[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.
------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@261132 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/PruneEH.cpp
test/Transforms/PruneEH/pr26263.ll

index c2f55d896ba783cd4f160f3019b9ea5950fc6de0..22a95fa03f7c569134346f1e9b4bd18983f76a18 100644 (file)
@@ -252,7 +252,8 @@ void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
   }
 
   if (TokenInst) {
   }
 
   if (TokenInst) {
-    changeToUnreachable(TokenInst->getNextNode(), /*UseLLVMTrap=*/false);
+    if (!isa<TerminatorInst>(TokenInst))
+      changeToUnreachable(TokenInst->getNextNode(), /*UseLLVMTrap=*/false);
   } else {
     // Get the list of successors of this block.
     std::vector<BasicBlock *> Succs(succ_begin(BB), succ_end(BB));
   } else {
     // Get the list of successors of this block.
     std::vector<BasicBlock *> Succs(succ_begin(BB), succ_end(BB));
index 3670f00d8111f6e0e6c602f16f8a18eca4f96d38..17fafeb685057f432c241352817d1522d9785dc1 100644 (file)
@@ -27,4 +27,30 @@ cleanupret:
 
 ; CHECK: cleanupret from %[[cp]] unwind to caller
 
 
 ; 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(...)
 declare i32 @__CxxFrameHandler3(...)