[WinEH] Make FuncletLayout more robust against catchret
[oota-llvm.git] / test / CodeGen / X86 / funclet-layout.ll
1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
2
3 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-pc-windows-msvc"
5
6 %eh.ThrowInfo = type { i32, i32, i32, i32 }
7
8 define void @test1(i1 %B) personality i32 (...)* @__CxxFrameHandler3 {
9 entry:
10   invoke void @g()
11           to label %unreachable unwind label %catch.dispatch
12
13 catch.dispatch:
14   %cp = catchpad [i8* null, i32 64, i8* null]
15           to label %catch unwind label %catchendblock
16
17 catch:
18   br i1 %B, label %catchret, label %catch
19
20 catchret:
21   catchret %cp to label %try.cont
22
23 try.cont:
24   ret void
25
26 catchendblock:
27   catchendpad unwind to caller
28
29 unreachable:
30   unreachable
31 }
32
33 ; CHECK-LABEL: test1:
34
35 ; The entry funclet contains %entry and %try.cont
36 ; CHECK: # %entry
37 ; CHECK: # %try.cont
38 ; CHECK: retq
39
40 ; The catch funclet contains %catch and %catchret
41 ; CHECK: # %catch
42 ; CHECK: # %catchret
43 ; CHECK: retq
44
45 declare void @g()
46
47
48 define i32 @test2(i1 %B) personality i32 (...)* @__CxxFrameHandler3 {
49 entry:
50   invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1
51           to label %unreachable unwind label %catch.dispatch
52
53 catch.dispatch:                                   ; preds = %entry
54   %0 = catchpad [i8* null, i32 64, i8* null]
55           to label %catch unwind label %catchendblock
56
57 catch:                                            ; preds = %catch.dispatch
58   invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1
59           to label %unreachable unwind label %catch.dispatch.1
60
61 catch.dispatch.1:                                 ; preds = %catch
62   %1 = catchpad [i8* null, i32 64, i8* null]
63           to label %catch.3 unwind label %catchendblock.2
64
65 catch.3:                                          ; preds = %catch.dispatch.1
66   catchret %1 to label %try.cont
67
68 try.cont:                                         ; preds = %catch.3
69   catchret %0 to label %try.cont.5
70
71 try.cont.5:                                       ; preds = %try.cont
72   ret i32 0
73
74 catchendblock.2:                                  ; preds = %catch.dispatch.1
75   catchendpad unwind label %catchendblock
76
77 catchendblock:                                    ; preds = %catchendblock.2, %catch.dispatch
78   catchendpad unwind to caller
79
80 unreachable:                                      ; preds = %catch, %entry
81   unreachable
82
83 }
84
85 ; CHECK-LABEL: test2:
86
87 ; The entry funclet contains %entry and %try.cont.5
88 ; CHECK: # %entry
89 ; CHECK: # %try.cont.5
90 ; CHECK: retq
91
92 ; The inner catch funclet contains %catch.3
93 ; CHECK: # %catch.3
94 ; CHECK: retq
95
96 ; The outer catch funclet contains %catch and %try.cont
97 ; CHECK: # %catch
98 ; CHECK: # %try.cont
99 ; CHECK: retq
100
101 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
102 declare i32 @__CxxFrameHandler3(...)