[SimplifyCFG] Don't DCE catchret because the successor is unreachable
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 27 Oct 2015 22:43:56 +0000 (22:43 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 27 Oct 2015 22:43:56 +0000 (22:43 +0000)
CatchReturnInst has side-effects: it runs a destructor.  This destructor
could conceivably run forever/call exit/etc. and should not be removed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251461 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/wineh-unreachable.ll

index e435537c3a7d7c3db7f23c2c5c2e1ca4292c3ad8..69c08e55283a05c2a0808bfbd3ba5f51661fcd2a 100644 (file)
@@ -3178,8 +3178,7 @@ bool SimplifyCFGOpt::SimplifyUnreachable(UnreachableInst *UI) {
                isa<CatchEndPadInst>(TI) || isa<TerminatePadInst>(TI)) {
       removeUnwindEdge(TI->getParent());
       Changed = true;
-    } else if (isa<CleanupReturnInst>(TI) || isa<CleanupEndPadInst>(TI) ||
-               isa<CatchReturnInst>(TI)) {
+    } else if (isa<CleanupReturnInst>(TI) || isa<CleanupEndPadInst>(TI)) {
       new UnreachableInst(TI->getContext(), TI);
       TI->eraseFromParent();
       Changed = true;
index 7db883b2412bb28fae8b73b210fd470888dfa30b..31d567f649208adf4e212218168617e53b0010db 100644 (file)
@@ -86,3 +86,23 @@ unreachable.unwind:
   cleanuppad []
   unreachable
 }
+
+; CHECK-LABEL: define void @test5()
+define void @test5() personality i8* bitcast (void ()* @Personality to i8*) {
+entry:
+  invoke void @f()
+          to label %exit unwind label %catch.pad
+
+catch.pad:
+  %catch = catchpad []
+          to label %catch.body unwind label %catch.end
+
+catch.body:
+  catchret %catch to label %exit
+
+catch.end:
+  catchendpad unwind to caller
+
+exit:
+  unreachable
+}