1; RUN: opt -S -simplifycfg < %s | FileCheck %s
2
3declare void @Personality()
4declare void @f()
5
6; CHECK-LABEL: define void @test1()
7define void @test1() personality i8* bitcast (void ()* @Personality to i8*) {
8entry:
9  ; CHECK: call void @f()
10  invoke void @f()
11    to label %exit unwind label %unreachable.unwind
12exit:
13  ret void
14unreachable.unwind:
15  cleanuppad within none []
16  unreachable
17}
18
19; CHECK-LABEL: define void @test2()
20define void @test2() personality i8* bitcast (void ()* @Personality to i8*) {
21entry:
22  invoke void @f()
23    to label %exit unwind label %catch.pad
24catch.pad:
25  %cs1 = catchswitch within none [label %catch.body] unwind label %unreachable.unwind
26  ; CHECK: catch.pad:
27  ; CHECK-NEXT: catchswitch within none [label %catch.body] unwind to caller
28catch.body:
29  ; CHECK:      catch.body:
30  ; CHECK-NEXT:   catchpad within %cs1
31  ; CHECK-NEXT:   call void @f()
32  ; CHECK-NEXT:   unreachable
33  %catch = catchpad within %cs1 []
34  call void @f()
35  catchret from %catch to label %unreachable
36exit:
37  ret void
38unreachable.unwind:
39  cleanuppad within none []
40  unreachable
41unreachable:
42  unreachable
43}
44
45; CHECK-LABEL: define void @test3()
46define void @test3() personality i8* bitcast (void ()* @Personality to i8*) {
47entry:
48  invoke void @f()
49    to label %exit unwind label %cleanup.pad
50cleanup.pad:
51  ; CHECK: %cleanup = cleanuppad within none []
52  ; CHECK-NEXT: call void @f()
53  ; CHECK-NEXT: unreachable
54  %cleanup = cleanuppad within none []
55  invoke void @f()
56    to label %cleanup.ret unwind label %unreachable.unwind
57cleanup.ret:
58  ; This cleanupret should be rewritten to unreachable,
59  ; and merged into the pred block.
60  cleanupret from %cleanup unwind label %unreachable.unwind
61exit:
62  ret void
63unreachable.unwind:
64  cleanuppad within none []
65  unreachable
66}
67
68; CHECK-LABEL: define void @test5()
69define void @test5() personality i8* bitcast (void ()* @Personality to i8*) {
70entry:
71  invoke void @f()
72          to label %exit unwind label %catch.pad
73
74catch.pad:
75  %cs1 = catchswitch within none [label %catch.body] unwind to caller
76
77catch.body:
78  %catch = catchpad within %cs1 []
79  catchret from %catch to label %exit
80
81exit:
82  unreachable
83}
84
85; CHECK-LABEL: define void @test6()
86define void @test6() personality i8* bitcast (void ()* @Personality to i8*) {
87entry:
88  invoke void @f()
89          to label %exit unwind label %catch.pad
90
91catch.pad:
92  %cs1 = catchswitch within none [label %catch.body, label %catch.body] unwind to caller
93  ; CHECK: catchswitch within none [label %catch.body] unwind to caller
94
95catch.body:
96  %catch = catchpad within %cs1 [i8* null, i32 0, i8* null]
97  catchret from %catch to label %exit
98
99exit:
100  ret void
101}
102
103; CHECK-LABEL: define void @test7()
104define void @test7() personality i8* bitcast (void ()* @Personality to i8*) {
105entry:
106  invoke void @f()
107          to label %exit unwind label %catch.pad
108
109catch.pad:
110  %cs1 = catchswitch within none [label %catch.body, label %catch.body2] unwind to caller
111  ; CHECK: catchswitch within none [label %catch.body] unwind to caller
112
113catch.body:
114  %catch = catchpad within %cs1 [i8* null, i32 0, i8* null]
115  catchret from %catch to label %exit
116
117catch.body2:
118  %catch2 = catchpad within %cs1 [i8* null, i32 0, i8* null]
119  catchret from %catch2 to label %exit
120
121exit:
122  ret void
123}
124
125; CHECK-LABEL: define void @test8()
126define void @test8() personality i8* bitcast (void ()* @Personality to i8*) {
127entry:
128  invoke void @f()
129          to label %exit unwind label %catch.pad
130
131catch.pad:
132  %cs1 = catchswitch within none [label %catch.body, label %catch.body2] unwind to caller
133  ; CHECK: catchswitch within none [label %catch.body] unwind to caller
134
135catch.body2:
136  %catch2 = catchpad within %cs1 [i8* null, i32 0, i8* null]
137  catchret from %catch2 to label %exit
138
139catch.body:
140  %catch = catchpad within %cs1 [i8* null, i32 0, i8* null]
141  catchret from %catch to label %exit
142
143exit:
144  ret void
145}
146
147; CHECK-LABEL: define void @test9()
148define void @test9() personality i8* bitcast (void ()* @Personality to i8*) {
149entry:
150  invoke void @f()
151          to label %exit unwind label %catch.pad
152
153catch.pad:
154  %cs1 = catchswitch within none [label %catch.body, label %catch.body2] unwind to caller
155  ; CHECK: catchswitch within none [label %catch.body, label %catch.body2] unwind to caller
156
157catch.body:
158  %catch = catchpad within %cs1 [i8* null, i32 0, i8* null]
159  catchret from %catch to label %exit
160
161catch.body2:
162  %catch2 = catchpad within %cs1 [i8* null, i32 64, i8* null]
163  catchret from %catch2 to label %exit
164
165exit:
166  ret void
167}
168