blob: 97dbea5b1f59aae3533e323ae0e86d6dfa5abaed [file] [log] [blame]
Andrew Kaylor6b67d422015-03-11 23:22:06 +00001; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2
3; This test is based on the following code:
4;
5; class Inner {
6; public:
7; Inner();
8; ~Inner();
9; };
10; class Outer {
11; public:
12; Outer();
13; ~Outer();
14; };
15; void test() {
16; try {
17; Outer outer;
18; try {
19; Inner inner;
20; may_throw();
21; } catch (int i) {
22; handle_int(i);
23; }
24; } catch (float f) {
25; handle_float(f);
26; }
27; done();
28; }
29
30; ModuleID = 'nested-2.cpp'
31target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
32target triple = "x86_64-pc-windows-msvc"
33
34%class.Outer = type { i8 }
35%class.Inner = type { i8 }
36
37@_ZTIf = external constant i8*
38@_ZTIi = external constant i8*
39
40; The function entry should be rewritten like this.
41; CHECK: define void @_Z4testv() #0 {
42; CHECK: entry:
43; CHECK: %outer = alloca %class.Outer, align 1
44; CHECK: %inner = alloca %class.Inner, align 1
45; CHECK: %i = alloca i32, align 4
46; CHECK: %f = alloca float, align 4
47; CHECK: call void (...)* @llvm.frameescape(float* %f, i32* %i, %class.Outer* %outer, %class.Inner* %inner)
48; CHECK: invoke void @_ZN5OuterC1Ev(%class.Outer* %outer)
49; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
50
51; Function Attrs: uwtable
52define void @_Z4testv() #0 {
53entry:
54 %outer = alloca %class.Outer, align 1
55 %exn.slot = alloca i8*
56 %ehselector.slot = alloca i32
57 %inner = alloca %class.Inner, align 1
58 %i = alloca i32, align 4
59 %f = alloca float, align 4
60 invoke void @_ZN5OuterC1Ev(%class.Outer* %outer)
61 to label %invoke.cont unwind label %lpad
62
63; CHECK: invoke.cont:
64; CHECK: invoke void @_ZN5InnerC1Ev(%class.Inner* %inner)
65; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]*]]
66
67invoke.cont: ; preds = %entry
68 invoke void @_ZN5InnerC1Ev(%class.Inner* %inner)
69 to label %invoke.cont2 unwind label %lpad1
70
71; CHECK: invoke.cont2:
72; CHECK: invoke void @_Z9may_throwv()
73; CHECK: to label %invoke.cont4 unwind label %[[LPAD3_LABEL:lpad[0-9]*]]
74
75invoke.cont2: ; preds = %invoke.cont
76 invoke void @_Z9may_throwv()
77 to label %invoke.cont4 unwind label %lpad3
78
79; CHECK: invoke.cont4:
80; CHECK: invoke void @_ZN5InnerD1Ev(%class.Inner* %inner)
81; CHECK: to label %invoke.cont5 unwind label %[[LPAD1_LABEL]]
82
83invoke.cont4: ; preds = %invoke.cont2
84 invoke void @_ZN5InnerD1Ev(%class.Inner* %inner)
85 to label %invoke.cont5 unwind label %lpad1
86
87; CHECK: invoke.cont5:
88; CHECK: br label %try.cont
89
90invoke.cont5: ; preds = %invoke.cont4
91 br label %try.cont
92
93; CHECK: [[LPAD_LABEL]]:
94; CHECK: [[LPAD_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
95; CHECK: catch i8* bitcast (i8** @_ZTIf to i8*)
96; CHECK: [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD_VAL]], i32 0, i8* bitcast (i8** @_ZTIf to i8*), float* %f, i8* bitcast (i8* (i8*, i8*)* @_Z4testv.catch to i8*))
97; CHECK: indirectbr i8* [[RECOVER]], [label %try.cont19]
98
99lpad: ; preds = %try.cont, %entry
100 %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
101 catch i8* bitcast (i8** @_ZTIf to i8*)
102 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
103 store i8* %tmp1, i8** %exn.slot
104 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
105 store i32 %tmp2, i32* %ehselector.slot
106 br label %catch.dispatch11
107
108; CHECK: [[LPAD1_LABEL]]:
109; CHECK: [[LPAD1_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
110; CHECK: cleanup
111; CHECK: catch i8* bitcast (i8** @_ZTIi to i8*)
112; CHECK: catch i8* bitcast (i8** @_ZTIf to i8*)
113; CHECK: [[RECOVER1:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD1_VAL]], i32 0, i8* bitcast (i8** @_ZTIi to i8*), i32* %i, i8* bitcast (i8* (i8*, i8*)* @_Z4testv.catch1 to i8*), i32 1, i8* bitcast (void (i8*, i8*)* @_Z4testv.cleanup to i8*), i32 0, i8* bitcast (i8** @_ZTIf to i8*), float* %f, i8* bitcast (i8* (i8*, i8*)* @_Z4testv.catch to i8*))
114; CHECK: indirectbr i8* [[RECOVER1]], [label %try.cont, label %try.cont19]
115
116lpad1: ; preds = %invoke.cont4, %invoke.cont
117 %tmp3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
118 cleanup
119 catch i8* bitcast (i8** @_ZTIi to i8*)
120 catch i8* bitcast (i8** @_ZTIf to i8*)
121 %tmp4 = extractvalue { i8*, i32 } %tmp3, 0
122 store i8* %tmp4, i8** %exn.slot
123 %tmp5 = extractvalue { i8*, i32 } %tmp3, 1
124 store i32 %tmp5, i32* %ehselector.slot
125 br label %catch.dispatch
126
127; CHECK: [[LPAD3_LABEL]]:
128; CHECK: [[LPAD3_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
129; CHECK: cleanup
130; CHECK: catch i8* bitcast (i8** @_ZTIi to i8*)
131; CHECK: catch i8* bitcast (i8** @_ZTIf to i8*)
132; CHECK-NOT: extractvalue { i8*, i32 }
133; CHECK-NOT: store i8*
134; CHECK-NOT: store i32
135; CHECK-NOT: call void @_ZN5InnerD1Ev(%class.Inner* %inner)
136; CHECK: [[RECOVER3:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD3_VAL]], i32 1, i8* bitcast (void (i8*, i8*)* @_Z4testv.cleanup2 to i8*), i32 0, i8* bitcast (i8** @_ZTIi to i8*), i32* %i, i8* bitcast (i8* (i8*, i8*)* @_Z4testv.catch1 to i8*), i32 1, i8* bitcast (void (i8*, i8*)* @_Z4testv.cleanup to i8*), i32 0, i8* bitcast (i8** @_ZTIf to i8*), float* %f, i8* bitcast (i8* (i8*, i8*)* @_Z4testv.catch to i8*))
137; CHECK: indirectbr i8* [[RECOVER3]], [label %try.cont, label %try.cont19]
138
139lpad3: ; preds = %invoke.cont2
140 %tmp6 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
141 cleanup
142 catch i8* bitcast (i8** @_ZTIi to i8*)
143 catch i8* bitcast (i8** @_ZTIf to i8*)
144 %tmp7 = extractvalue { i8*, i32 } %tmp6, 0
145 store i8* %tmp7, i8** %exn.slot
146 %tmp8 = extractvalue { i8*, i32 } %tmp6, 1
147 store i32 %tmp8, i32* %ehselector.slot
148 call void @_ZN5InnerD1Ev(%class.Inner* %inner)
149 br label %catch.dispatch
150
151; CHECK-NOT: catch.dispatch:
152
153catch.dispatch: ; preds = %lpad3, %lpad1
154 %sel = load i32, i32* %ehselector.slot
155 %tmp9 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #4
156 %matches = icmp eq i32 %sel, %tmp9
157 br i1 %matches, label %catch, label %ehcleanup
158
159; CHECK-NOT: catch:
160
161catch: ; preds = %catch.dispatch
162 %exn = load i8*, i8** %exn.slot
163 %i.i8 = bitcast i32* %i to i8*
164 call void @llvm.eh.begincatch(i8* %exn, i8* %i.i8) #4
165 %tmp13 = load i32, i32* %i, align 4
166 invoke void @_Z10handle_inti(i32 %tmp13)
167 to label %invoke.cont8 unwind label %lpad7
168
169; CHECK-NOT: invoke.cont8:
170
171invoke.cont8: ; preds = %catch
172 call void @llvm.eh.endcatch() #4
173 br label %try.cont
174
175; CHECK: try.cont:
176; CHECK: invoke void @_ZN5OuterD1Ev(%class.Outer* %outer)
177; CHECK: to label %invoke.cont9 unwind label %[[LPAD_LABEL]]
178
179try.cont: ; preds = %invoke.cont8, %invoke.cont5
180 invoke void @_ZN5OuterD1Ev(%class.Outer* %outer)
181 to label %invoke.cont9 unwind label %lpad
182
183invoke.cont9: ; preds = %try.cont
184 br label %try.cont19
185
186; CHECK-NOT: lpad7:
187
188lpad7: ; preds = %catch
189 %tmp14 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
190 cleanup
191 catch i8* bitcast (i8** @_ZTIf to i8*)
192 %tmp15 = extractvalue { i8*, i32 } %tmp14, 0
193 store i8* %tmp15, i8** %exn.slot
194 %tmp16 = extractvalue { i8*, i32 } %tmp14, 1
195 store i32 %tmp16, i32* %ehselector.slot
196 call void @llvm.eh.endcatch() #4
197 br label %ehcleanup
198
199; CHECK-NOT: ehcleanup: ; preds = %lpad7, %catch.dispatch
200
201ehcleanup: ; preds = %lpad7, %catch.dispatch
202 call void @_ZN5OuterD1Ev(%class.Outer* %outer)
203 br label %catch.dispatch11
204
205; CHECK-NOT: catch.dispatch11:
206
207catch.dispatch11: ; preds = %ehcleanup, %lpad
208 %sel12 = load i32, i32* %ehselector.slot
209 %tmp17 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIf to i8*)) #4
210 %matches13 = icmp eq i32 %sel12, %tmp17
211 br i1 %matches13, label %catch14, label %eh.resume
212
213; CHECK-NOT: catch14:
214
215catch14: ; preds = %catch.dispatch11
216 %exn15 = load i8*, i8** %exn.slot
217 %f.i8 = bitcast float* %f to i8*
218 call void @llvm.eh.begincatch(i8* %exn15, i8* %f.i8) #4
219 %tmp21 = load float, float* %f, align 4
220 call void @_Z12handle_floatf(float %tmp21)
221 call void @llvm.eh.endcatch() #4
222 br label %try.cont19
223
224try.cont19: ; preds = %catch14, %invoke.cont9
225 call void @_Z4donev()
226 ret void
227
228; CHECK-NOT: eh.resume:
229
230eh.resume: ; preds = %catch.dispatch11
231 %exn20 = load i8*, i8** %exn.slot
232 %sel21 = load i32, i32* %ehselector.slot
233 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn20, 0
234 %lpad.val22 = insertvalue { i8*, i32 } %lpad.val, i32 %sel21, 1
235 resume { i8*, i32 } %lpad.val22
236
237; CHECK: }
238}
239
240; This catch handler should be outlined.
241; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
242; CHECK: entry:
243; CHECK: [[RECOVER_F:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 0)
244; CHECK: [[F_PTR:\%.+]] = bitcast i8* [[RECOVER_F]] to float*
245; CHECK: [[TMP:\%.+]] = load float, float* [[F_PTR]], align 4
246; CHECK: call void @_Z12handle_floatf(float [[TMP]])
247; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont19)
248; CHECK: }
249
250; This catch handler should be outlined.
251; CHECK: define internal i8* @_Z4testv.catch1(i8*, i8*) {
252; CHECK: entry:
253; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 1)
254; CHECK: [[I_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
255; CHECK: [[TMP1:\%.+]] = load i32, i32* [[I_PTR]], align 4
256; CHECK: invoke void @_Z10handle_inti(i32 [[TMP1]])
257; CHECK: to label %invoke.cont8 unwind label %[[LPAD7_LABEL:lpad[0-9]*]]
258;
259; CHECK: invoke.cont8: ; preds = %entry
260; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
261;
262; CHECK: [[LPAD7_LABEL]]:{{[ ]+}}; preds = %entry
263; CHECK: [[LPAD7_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
264; (FIXME) The nested handler body isn't being populated yet.
265; CHECK: }
266
267; This cleanup handler should be outlined.
268; CHECK: define internal void @_Z4testv.cleanup(i8*, i8*) {
269; CHECK: entry:
270; CHECK: [[RECOVER_OUTER:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 2)
271; CHECK: [[OUTER_PTR:\%.+]] = bitcast i8* [[RECOVER_OUTER]] to %class.Outer*
272; CHECK: call void @_ZN5OuterD1Ev(%class.Outer* [[OUTER_PTR]])
273; CHECK: ret void
274; CHECK: }
275
276; This cleanup handler should be outlined.
277; CHECK: define internal void @_Z4testv.cleanup2(i8*, i8*) {
278; CHECK: entry:
279; CHECK: [[RECOVER_INNER:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 3)
280; CHECK: [[INNER_PTR:\%.+]] = bitcast i8* [[RECOVER_INNER]] to %class.Inner*
281; CHECK: call void @_ZN5InnerD1Ev(%class.Inner* [[INNER_PTR]])
282; CHECK: ret void
283; CHECK: }
284
285
286
287declare void @_ZN5OuterC1Ev(%class.Outer*) #1
288
289declare i32 @__CxxFrameHandler3(...)
290
291declare void @_ZN5InnerC1Ev(%class.Inner*) #1
292
293declare void @_Z9may_throwv() #1
294
295declare void @_ZN5InnerD1Ev(%class.Inner*) #1
296
297declare void @llvm.eh.begincatch(i8*, i8*)
298
299; Function Attrs: nounwind readnone
300declare i32 @llvm.eh.typeid.for(i8*) #3
301
302declare void @_Z10handle_inti(i32) #1
303
304declare void @llvm.eh.endcatch()
305
306declare void @_ZN5OuterD1Ev(%class.Outer*) #1
307
308declare void @_Z12handle_floatf(float) #1
309
310declare void @_Z4donev() #1
311
312attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
313attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
314attributes #2 = { noinline noreturn nounwind }
315attributes #3 = { nounwind readnone }
316attributes #4 = { nounwind }
317attributes #5 = { noreturn nounwind }
318
319!llvm.ident = !{!0}
320
321!0 = !{!"clang version 3.7.0 (trunk 226027)"}