[WinEH] Fix CatchRetSuccessorColorMap accounting
authorJoseph Tremoulet <jotrem@microsoft.com>
Fri, 16 Oct 2015 21:22:54 +0000 (21:22 +0000)
committerJoseph Tremoulet <jotrem@microsoft.com>
Fri, 16 Oct 2015 21:22:54 +0000 (21:22 +0000)
Summary:
We now use the block for the catchpad itself, rather than its normal
successor, as the funclet entry.
Putting the normal successor in the map leads downstream funclet
membership computations to erroneous results.

Reviewers: majnemer, rnk

Subscribers: rnk, llvm-commits

Differential Revision: http://reviews.llvm.org/D13798

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

lib/CodeGen/WinEHPrepare.cpp
test/CodeGen/X86/win-catchpad-nested.ll [new file with mode: 0644]

index 957064891d7189d44dc35a9e8e801b86bce11618..ca69d321f3b3d3fb89a0ae97e6c1ca5f5354c0eb 100644 (file)
@@ -703,8 +703,6 @@ void llvm::calculateCatchReturnSuccessorColors(const Function *Fn,
       std::set<BasicBlock *> &SuccessorColors = BlockColors[CatchRetSuccessor];
       assert(SuccessorColors.size() == 1 && "Expected BB to be monochrome!");
       BasicBlock *Color = *SuccessorColors.begin();
-      if (auto *CPI = dyn_cast<CatchPadInst>(Color->getFirstNonPHI()))
-        Color = CPI->getNormalDest();
       // Record the catchret successor's funclet membership.
       FuncInfo.CatchRetSuccessorColorMap[CatchReturn] = Color;
     }
diff --git a/test/CodeGen/X86/win-catchpad-nested.ll b/test/CodeGen/X86/win-catchpad-nested.ll
new file mode 100644 (file)
index 0000000..d803aae
--- /dev/null
@@ -0,0 +1,41 @@
+; RUN: llc -mtriple=x86_64-pc-windows-coreclr < %s | FileCheck %s
+
+declare void @ProcessCLRException()
+
+declare void @f()
+
+define void @test1() personality void ()* @ProcessCLRException {
+entry:
+  invoke void @f()
+          to label %exit unwind label %outer.pad
+outer.pad:
+  %outer = catchpad [i32 1]
+          to label %outer.catch unwind label %outer.end
+outer.catch:
+  invoke void @f()
+          to label %outer.ret unwind label %inner.pad
+inner.pad:
+  %inner = catchpad [i32 2]
+          to label %inner.ret unwind label %inner.end
+inner.ret:
+  catchret %inner to label %outer.ret
+inner.end:
+  catchendpad unwind label %outer.end
+outer.ret:
+  catchret %outer to label %exit
+outer.end:
+  catchendpad unwind to caller
+exit:
+  ret void
+}
+
+; Check the catchret targets
+; CHECK-LABEL: test1: # @test1
+; CHECK: [[Exit:^[^: ]+]]: # %exit
+; CHECK: [[OuterRet:^[^: ]+]]: # %outer.ret
+; CHECK-NEXT: leaq [[Exit]](%rip), %rax
+; CHECK:      retq   # CATCHRET
+; CHECK: {{^[^: ]+}}: # %inner.pad
+; CHECK: .seh_endprolog
+; CHECK-NEXT: leaq [[OuterRet]](%rip), %rax
+; CHECK:      retq   # CATCHRET