blob: 362e03d36a3233b28150d3cb3e0f6607ec0bec97 [file] [log] [blame]
Joseph Tremouletb41632b2016-01-20 02:15:15 +00001; RUN: opt -inline -S %s | FileCheck %s
2
3declare void @g()
4
5
6;;; Test with a call in a funclet that needs to remain a call
7;;; when inlined because the funclet doesn't unwind to caller.
8;;; CHECK-LABEL: define void @test1(
9define void @test1() personality void ()* @g {
10entry:
11; CHECK-NEXT: entry:
12 invoke void @test1_inlinee()
13 to label %exit unwind label %cleanup
14cleanup:
15 %pad = cleanuppad within none []
16 call void @g() [ "funclet"(token %pad) ]
17 cleanupret from %pad unwind to caller
18exit:
19 ret void
20}
21
22define void @test1_inlinee() alwaysinline personality void ()* @g {
23entry:
24 invoke void @g()
25 to label %exit unwind label %cleanup.inner
26; CHECK-NEXT: invoke void @g()
27; CHECK-NEXT: unwind label %[[cleanup_inner:.+]]
28
29cleanup.inner:
30 %pad.inner = cleanuppad within none []
31 call void @g() [ "funclet"(token %pad.inner) ]
32 cleanupret from %pad.inner unwind label %cleanup.outer
33; CHECK: [[cleanup_inner]]:
34; The call here needs to remain a call becuase pad.inner has a cleanupret
35; that stays within the inlinee.
36; CHECK-NEXT: %[[pad_inner:[^ ]+]] = cleanuppad within none
37; CHECK-NEXT: call void @g() [ "funclet"(token %[[pad_inner]]) ]
38; CHECK-NEXT: cleanupret from %[[pad_inner]] unwind label %[[cleanup_outer:.+]]
39
40cleanup.outer:
41 %pad.outer = cleanuppad within none []
42 call void @g() [ "funclet"(token %pad.outer) ]
43 cleanupret from %pad.outer unwind to caller
44; CHECK: [[cleanup_outer]]:
45; The call and cleanupret here need to be redirected to caller cleanup
46; CHECK-NEXT: %[[pad_outer:[^ ]+]] = cleanuppad within none
47; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[pad_outer]]) ]
48; CHECK-NEXT: unwind label %cleanup
49; CHECK: cleanupret from %[[pad_outer]] unwind label %cleanup{{$}}
50
51exit:
52 ret void
53}
54
55
56
57;;; Test with an "unwind to caller" catchswitch in a parent funclet
58;;; that needs to remain "unwind to caller" because the parent
59;;; doesn't unwind to caller.
60;;; CHECK-LABEL: define void @test2(
61define void @test2() personality void ()* @g {
62entry:
63; CHECK-NEXT: entry:
64 invoke void @test2_inlinee()
65 to label %exit unwind label %cleanup
66cleanup:
67 %pad = cleanuppad within none []
68 call void @g() [ "funclet"(token %pad) ]
69 cleanupret from %pad unwind to caller
70exit:
71 ret void
72}
73
74define void @test2_inlinee() alwaysinline personality void ()* @g {
75entry:
76 invoke void @g()
77 to label %exit unwind label %cleanup1
78; CHECK-NEXT: invoke void @g()
79; CHECK-NEXT: unwind label %[[cleanup1:.+]]
80
81cleanup1:
82 %outer = cleanuppad within none []
83 invoke void @g() [ "funclet"(token %outer) ]
84 to label %ret1 unwind label %catchswitch
85; CHECK: [[cleanup1]]:
86; CHECK-NEXT: %[[outer:[^ ]+]] = cleanuppad within none
87; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[outer]]) ]
88; CHECK-NEXT: unwind label %[[catchswitch:.+]]
89
90catchswitch:
91 %cs = catchswitch within %outer [label %catch] unwind to caller
92; CHECK: [[catchswitch]]:
93; The catchswitch here needs to remain "unwind to caller" since %outer
94; has a cleanupret that remains within the inlinee.
95; CHECK-NEXT: %[[cs:[^ ]+]] = catchswitch within %[[outer]] [label %[[catch:.+]]] unwind to caller
96
97catch:
98 %inner = catchpad within %cs []
99 call void @g() [ "funclet"(token %inner) ]
100 catchret from %inner to label %ret1
101; CHECK: [[catch]]:
102; The call here needs to remain a call since it too is within %outer
103; CHECK: %[[inner:[^ ]+]] = catchpad within %[[cs]]
104; CHECK-NEXT: call void @g() [ "funclet"(token %[[inner]]) ]
105
106ret1:
107 cleanupret from %outer unwind label %cleanup2
108; CHECK: cleanupret from %[[outer]] unwind label %[[cleanup2:.+]]
109
110cleanup2:
111 %later = cleanuppad within none []
112 cleanupret from %later unwind to caller
113; CHECK: [[cleanup2]]:
114; The cleanupret here needs to get redirected to the caller cleanup
115; CHECK-NEXT: %[[later:[^ ]+]] = cleanuppad within none
116; CHECK-NEXT: cleanupret from %[[later]] unwind label %cleanup{{$}}
117
118exit:
119 ret void
120}
121
122
123;;; Test with a call in a cleanup that has no definitive unwind
124;;; destination, that must be rewritten to an invoke.
125;;; CHECK-LABEL: define void @test3(
126define void @test3() personality void ()* @g {
127entry:
128; CHECK-NEXT: entry:
129 invoke void @test3_inlinee()
130 to label %exit unwind label %cleanup
131cleanup:
132 %pad = cleanuppad within none []
133 call void @g() [ "funclet"(token %pad) ]
134 cleanupret from %pad unwind to caller
135exit:
136 ret void
137}
138
139define void @test3_inlinee() alwaysinline personality void ()* @g {
140entry:
141 invoke void @g()
142 to label %exit unwind label %cleanup
143; CHECK-NEXT: invoke void @g()
144; CHECK-NEXT: unwind label %[[cleanup:.+]]
145
146cleanup:
147 %pad = cleanuppad within none []
148 call void @g() [ "funclet"(token %pad) ]
149 unreachable
150; CHECK: [[cleanup]]:
151; The call must be rewritten to an invoke targeting the caller cleanup
152; because it may well unwind to there.
153; CHECK-NEXT: %[[pad:[^ ]+]] = cleanuppad within none
154; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[pad]]) ]
155; CHECK-NEXT: unwind label %cleanup{{$}}
156
157exit:
158 ret void
159}
160
161
162;;; Test with a catchswitch in a cleanup that has no definitive
163;;; unwind destination, that must be rewritten to unwind to the
164;;; inlined invoke's unwind dest
165;;; CHECK-LABEL: define void @test4(
166define void @test4() personality void ()* @g {
167entry:
168; CHECK-NEXT: entry:
169 invoke void @test4_inlinee()
170 to label %exit unwind label %cleanup
171cleanup:
172 %pad = cleanuppad within none []
173 call void @g() [ "funclet"(token %pad) ]
174 cleanupret from %pad unwind to caller
175exit:
176 ret void
177}
178
179define void @test4_inlinee() alwaysinline personality void ()* @g {
180entry:
181 invoke void @g()
182 to label %exit unwind label %cleanup
183; CHECK-NEXT: invoke void @g()
184; CHECK-NEXT: unwind label %[[cleanup:.+]]
185
186cleanup:
187 %clean = cleanuppad within none []
188 invoke void @g() [ "funclet"(token %clean) ]
189 to label %unreachable unwind label %dispatch
190; CHECK: [[cleanup]]:
191; CHECK-NEXT: %[[clean:[^ ]+]] = cleanuppad within none
192; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[clean]]) ]
193; CHECK-NEXT: unwind label %[[dispatch:.+]]
194
195dispatch:
196 %cs = catchswitch within %clean [label %catch] unwind to caller
197; CHECK: [[dispatch]]:
198; The catchswitch must be rewritten to unwind to %cleanup in the caller
199; because it may well unwind to there.
200; CHECK-NEXT: %[[cs:[^ ]+]] = catchswitch within %[[clean]] [label %[[catch:.+]]] unwind label %cleanup{{$}}
201
202catch:
203 catchpad within %cs []
204 br label %unreachable
205unreachable:
206 unreachable
207exit:
208 ret void
209}
210
211
212;;; Test with multiple levels of nesting, and unwind dests
213;;; that need to be inferred from ancestors, descendants,
214;;; and cousins.
215;;; CHECK-LABEL: define void @test5(
216define void @test5() personality void ()* @g {
217entry:
218; CHECK-NEXT: entry:
219 invoke void @test5_inlinee()
220 to label %exit unwind label %cleanup
221cleanup:
222 %pad = cleanuppad within none []
223 call void @g() [ "funclet"(token %pad) ]
224 cleanupret from %pad unwind to caller
225exit:
226 ret void
227}
228
229define void @test5_inlinee() alwaysinline personality void ()* @g {
230entry:
231 invoke void @g()
232 to label %cont unwind label %noinfo.root
233; CHECK-NEXT: invoke void @g()
234; CHECK-NEXT: to label %[[cont:[^ ]+]] unwind label %[[noinfo_root:.+]]
235
236noinfo.root:
237 %noinfo.root.pad = cleanuppad within none []
238 call void @g() [ "funclet"(token %noinfo.root.pad) ]
239 invoke void @g() [ "funclet"(token %noinfo.root.pad) ]
240 to label %noinfo.root.cont unwind label %noinfo.left
241; CHECK: [[noinfo_root]]:
242; Nothing under "noinfo.root" has a definitive unwind destination, so
243; we must assume all of it may actually unwind, and redirect unwinds
244; to the cleanup in the caller.
245; CHECK-NEXT: %[[noinfo_root_pad:[^ ]+]] = cleanuppad within none []
246; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_root_pad]]) ]
247; CHECK-NEXT: to label %[[next:[^ ]+]] unwind label %cleanup{{$}}
248; CHECK: [[next]]:
249; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_root_pad]]) ]
250; CHECK-NEXT: to label %[[noinfo_root_cont:[^ ]+]] unwind label %[[noinfo_left:.+]]
251
252noinfo.left:
253 %noinfo.left.pad = cleanuppad within %noinfo.root.pad []
254 invoke void @g() [ "funclet"(token %noinfo.left.pad) ]
255 to label %unreachable unwind label %noinfo.left.child
256; CHECK: [[noinfo_left]]:
257; CHECK-NEXT: %[[noinfo_left_pad:[^ ]+]] = cleanuppad within %[[noinfo_root_pad]]
258; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_left_pad]]) ]
259; CHECK-NEXT: unwind label %[[noinfo_left_child:.+]]
260
261noinfo.left.child:
262 %noinfo.left.child.cs = catchswitch within %noinfo.left.pad [label %noinfo.left.child.catch] unwind to caller
263; CHECK: [[noinfo_left_child]]:
264; CHECK-NEXT: %[[noinfo_left_child_cs:[^ ]+]] = catchswitch within %[[noinfo_left_pad]] [label %[[noinfo_left_child_catch:[^ ]+]]] unwind label %cleanup{{$}}
265
266noinfo.left.child.catch:
267 %noinfo.left.child.pad = catchpad within %noinfo.left.child.cs []
268 call void @g() [ "funclet"(token %noinfo.left.child.pad) ]
269 br label %unreachable
270; CHECK: [[noinfo_left_child_catch]]:
271; CHECK-NEXT: %[[noinfo_left_child_pad:[^ ]+]] = catchpad within %[[noinfo_left_child_cs]] []
272; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_left_child_pad]]) ]
273; CHECK-NEXT: unwind label %cleanup{{$}}
274
275noinfo.root.cont:
276 invoke void @g() [ "funclet"(token %noinfo.root.pad) ]
277 to label %unreachable unwind label %noinfo.right
278; CHECK: [[noinfo_root_cont]]:
279; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_root_pad]]) ]
280; CHECK-NEXT: unwind label %[[noinfo_right:.+]]
281
282noinfo.right:
283 %noinfo.right.cs = catchswitch within %noinfo.root.pad [label %noinfo.right.catch] unwind to caller
284; CHECK: [[noinfo_right]]:
285; CHECK-NEXT: %[[noinfo_right_cs:[^ ]+]] = catchswitch within %[[noinfo_root_pad]] [label %[[noinfo_right_catch:[^ ]+]]] unwind label %cleanup{{$}}
286
287noinfo.right.catch:
288 %noinfo.right.pad = catchpad within %noinfo.right.cs []
289 invoke void @g() [ "funclet"(token %noinfo.right.pad) ]
290 to label %unreachable unwind label %noinfo.right.child
291; CHECK: [[noinfo_right_catch]]:
292; CHECK-NEXT: %[[noinfo_right_pad:[^ ]+]] = catchpad within %[[noinfo_right_cs]]
293; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_right_pad]]) ]
294; CHECK-NEXT: unwind label %[[noinfo_right_child:.+]]
295
296noinfo.right.child:
297 %noinfo.right.child.pad = cleanuppad within %noinfo.right.pad []
298 call void @g() [ "funclet"(token %noinfo.right.child.pad) ]
299 br label %unreachable
300; CHECK: [[noinfo_right_child]]:
301; CHECK-NEXT: %[[noinfo_right_child_pad:[^ ]+]] = cleanuppad within %[[noinfo_right_pad]]
302; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_right_child_pad]]) ]
303; CHECK-NEXT: unwind label %cleanup{{$}}
304
305cont:
306 invoke void @g()
307 to label %exit unwind label %implicit.root
308; CHECK: [[cont]]:
309; CHECK-NEXT: invoke void @g()
310; CHECK-NEXT: unwind label %[[implicit_root:.+]]
311
312implicit.root:
313 %implicit.root.pad = cleanuppad within none []
314 call void @g() [ "funclet"(token %implicit.root.pad) ]
315 invoke void @g() [ "funclet"(token %implicit.root.pad) ]
316 to label %implicit.root.cont unwind label %implicit.left
317; CHECK: [[implicit_root]]:
318; There's an unwind edge to %internal in implicit.right, and we need to propagate that
319; fact down to implicit.right.grandchild, up to implicit.root, and down to
320; implicit.left.child.catch, leaving all calls and "unwind to caller" catchswitches
321; alone to so they don't conflict with the unwind edge in implicit.right
322; CHECK-NEXT: %[[implicit_root_pad:[^ ]+]] = cleanuppad within none
323; CHECK-NEXT: call void @g() [ "funclet"(token %[[implicit_root_pad]]) ]
324; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_root_pad]]) ]
325; CHECK-NEXT: to label %[[implicit_root_cont:[^ ]+]] unwind label %[[implicit_left:.+]]
326
327implicit.left:
328 %implicit.left.pad = cleanuppad within %implicit.root.pad []
329 invoke void @g() [ "funclet"(token %implicit.left.pad) ]
330 to label %unreachable unwind label %implicit.left.child
331; CHECK: [[implicit_left]]:
332; CHECK-NEXT: %[[implicit_left_pad:[^ ]+]] = cleanuppad within %[[implicit_root_pad:[^ ]+]]
333; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_left_pad]]) ]
334; CHECK-NEXT: unwind label %[[implicit_left_child:.+]]
335
336implicit.left.child:
337 %implicit.left.child.cs = catchswitch within %implicit.left.pad [label %implicit.left.child.catch] unwind to caller
338; CHECK: [[implicit_left_child]]:
339; CHECK-NEXT: %[[implicit_left_child_cs:[^ ]+]] = catchswitch within %[[implicit_left_pad]] [label %[[implicit_left_child_catch:[^ ]+]]] unwind to caller
340
341implicit.left.child.catch:
342 %implicit.left.child.pad = catchpad within %implicit.left.child.cs []
343 call void @g() [ "funclet"(token %implicit.left.child.pad) ]
344 br label %unreachable
345; CHECK: [[implicit_left_child_catch]]:
346; CHECK-NEXT: %[[implicit_left_child_pad:[^ ]+]] = catchpad within %[[implicit_left_child_cs]]
347; CHECK-NEXT: call void @g() [ "funclet"(token %[[implicit_left_child_pad]]) ]
348
349implicit.root.cont:
350 invoke void @g() [ "funclet"(token %implicit.root.pad) ]
351 to label %unreachable unwind label %implicit.right
352; CHECK: [[implicit_root_cont]]:
353; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_root_pad]]) ]
354; CHECK-NEXT: unwind label %[[implicit_right:.+]]
355
356implicit.right:
357 %implicit.right.cs = catchswitch within %implicit.root.pad [label %implicit.right.catch] unwind label %internal
358; CHECK: [[implicit_right]]:
359; This is the unwind edge (to %internal) whose existence needs to get propagated around the "implicit" tree
360; CHECK-NEXT: %[[implicit_right_cs:[^ ]+]] = catchswitch within %[[implicit_root_pad]] [label %[[implicit_right_catch:[^ ]+]]] unwind label %[[internal:.+]]
361
362implicit.right.catch:
363 %implicit.right.pad = catchpad within %implicit.right.cs []
364 invoke void @g() [ "funclet"(token %implicit.right.pad) ]
365 to label %unreachable unwind label %implicit.right.child
366; CHECK: [[implicit_right_catch]]:
367; CHECK-NEXT: %[[implicit_right_pad:[^ ]+]] = catchpad within %[[implicit_right_cs]]
368; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_right_pad]]) ]
369; CHECK-NEXT: unwind label %[[implicit_right_child:.+]]
370
371implicit.right.child:
372 %implicit.right.child.pad = cleanuppad within %implicit.right.pad []
373 invoke void @g() [ "funclet"(token %implicit.right.child.pad) ]
374 to label %unreachable unwind label %implicit.right.grandchild
375; CHECK: [[implicit_right_child]]:
376; CHECK-NEXT: %[[implicit_right_child_pad:[^ ]+]] = cleanuppad within %[[implicit_right_pad]]
377; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_right_child_pad]]) ]
378; CHECK-NEXT: unwind label %[[implicit_right_grandchild:.+]]
379
380implicit.right.grandchild:
381 %implicit.right.grandchild.cs = catchswitch within %implicit.right.child.pad [label %implicit.right.grandchild.catch] unwind to caller
382; CHECK: [[implicit_right_grandchild]]:
383; CHECK-NEXT: %[[implicit_right_grandchild_cs:[^ ]+]] = catchswitch within %[[implicit_right_child_pad]] [label %[[implicit_right_grandchild_catch:[^ ]+]]] unwind to caller
384
385implicit.right.grandchild.catch:
386 %implicit.right.grandhcild.pad = catchpad within %implicit.right.grandchild.cs []
387 call void @g() [ "funclet"(token %implicit.right.grandhcild.pad) ]
388 br label %unreachable
389; CHECK: [[implicit_right_grandchild_catch]]:
390; CHECK-NEXT: %[[implicit_right_grandhcild_pad:[^ ]+]] = catchpad within %[[implicit_right_grandchild_cs]]
391; CHECK-NEXT: call void @g() [ "funclet"(token %[[implicit_right_grandhcild_pad]]) ]
392
393internal:
394 %internal.pad = cleanuppad within none []
395 call void @g() [ "funclet"(token %internal.pad) ]
396 cleanupret from %internal.pad unwind to caller
397; CHECK: [[internal]]:
398; internal is a cleanup with a "return to caller" cleanuppad; that needs to get redirected
399; to %cleanup in the caller, and the call needs to get similarly rewritten to an invoke.
400; CHECK-NEXT: %[[internal_pad:[^ ]+]] = cleanuppad within none
401; CHECK-NEXT: invoke void @g() [ "funclet"(token %internal.pad.i) ]
402; CHECK-NEXT: to label %[[next:[^ ]+]] unwind label %cleanup{{$}}
403; CHECK: [[next]]:
404; CHECK-NEXT: cleanupret from %[[internal_pad]] unwind label %cleanup{{$}}
405
406unreachable:
407 unreachable
408exit:
409 ret void
410}
411
412
413declare void @ProcessCLRException()
414
415; Make sure the logic doesn't get tripped up when the inlined invoke is
416; itself within a funclet in the caller.
417; CHECK-LABEL: define void @test6(
418define void @test6() personality void ()* @ProcessCLRException {
419entry:
420 invoke void @g()
421 to label %exit unwind label %callsite_parent
422callsite_parent:
423 %callsite_parent.pad = cleanuppad within none []
424; CHECK: %callsite_parent.pad = cleanuppad within none
425 invoke void @test6_inlinee() [ "funclet"(token %callsite_parent.pad) ]
426 to label %ret unwind label %cleanup
427ret:
428 cleanupret from %callsite_parent.pad unwind label %cleanup
429cleanup:
430 %pad = cleanuppad within none []
431 call void @g() [ "funclet"(token %pad) ]
432 cleanupret from %pad unwind to caller
433exit:
434 ret void
435}
436
437define void @test6_inlinee() alwaysinline personality void ()* @ProcessCLRException {
438entry:
439 invoke void @g()
440 to label %exit unwind label %inlinee_cleanup
441; CHECK-NEXT: invoke void @g() [ "funclet"(token %callsite_parent.pad) ]
442; CHECK-NEXT: unwind label %[[inlinee_cleanup:.+]]
443
444inlinee_cleanup:
445 %inlinee.pad = cleanuppad within none []
446 call void @g() [ "funclet"(token %inlinee.pad) ]
447 unreachable
448; CHECK: [[inlinee_cleanup]]:
449; CHECK-NEXT: %[[inlinee_pad:[^ ]+]] = cleanuppad within %callsite_parent.pad
450; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[inlinee_pad]]) ]
451; CHECK-NEXT: unwind label %cleanup{{$}}
452
453exit:
454 ret void
455}