blob: 2cc2153dd8e1b6d4c8cdda533eb8c17bc69cd458 [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
Joseph Tremoulete92e0a92016-09-04 01:23:20 +0000412;;; Test with funclets that don't have information for themselves, but have
413;;; descendants which unwind to other descendants (left.left unwinds to
414;;; left.right, and right unwinds to far_right). Make sure that these local
415;;; unwinds don't trip up processing of the ancestor nodes (left and root) that
416;;; ultimately have no information.
417;;; CHECK-LABEL: define void @test6(
418define void @test6() personality void()* @ProcessCLRException {
419entry:
420; CHECK-NEXT: entry:
421 invoke void @test6_inlinee()
422 to label %exit unwind label %cleanup
423cleanup:
424 %pad = cleanuppad within none []
425 call void @g() [ "funclet"(token %pad) ]
426 cleanupret from %pad unwind to caller
427exit:
428 ret void
429}
430
431define void @test6_inlinee() alwaysinline personality void ()* @ProcessCLRException {
432entry:
433 invoke void @g()
434 to label %exit unwind label %root
435 ; CHECK-NEXT: invoke void @g()
436 ; CHECK-NEXT: unwind label %[[root:.+]]
437root:
438 %root.pad = cleanuppad within none []
439 invoke void @g() [ "funclet"(token %root.pad) ]
440 to label %root.cont unwind label %left
441; CHECK: [[root]]:
442; CHECK-NEXT: %[[root_pad:.+]] = cleanuppad within none []
443; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_pad]]) ]
444; CHECK-NEXT: to label %[[root_cont:.+]] unwind label %[[left:.+]]
445
446left:
447 %left.cs = catchswitch within %root.pad [label %left.catch] unwind to caller
448; CHECK: [[left]]:
449; CHECK-NEXT: %[[left_cs:.+]] = catchswitch within %[[root_pad]] [label %[[left_catch:.+]]] unwind label %cleanup
450
451left.catch:
452 %left.cp = catchpad within %left.cs []
453 call void @g() [ "funclet"(token %left.cp) ]
454 invoke void @g() [ "funclet"(token %left.cp) ]
455 to label %unreach unwind label %left.left
456; CHECK: [[left_catch:.+]]:
457; CHECK-NEXT: %[[left_cp:.+]] = catchpad within %[[left_cs]] []
458; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
459; CHECK-NEXT: to label %[[lc_cont:.+]] unwind label %cleanup
460; CHECK: [[lc_cont]]:
461; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
462; CHECK-NEXT: to label %[[unreach:.+]] unwind label %[[left_left:.+]]
463
464left.left:
465 %ll.pad = cleanuppad within %left.cp []
466 cleanupret from %ll.pad unwind label %left.right
467; CHECK: [[left_left]]:
468; CHECK-NEXT: %[[ll_pad:.+]] = cleanuppad within %[[left_cp]] []
469; CHECK-NEXT: cleanupret from %[[ll_pad]] unwind label %[[left_right:.+]]
470
471left.right:
472 %lr.pad = cleanuppad within %left.cp []
473 unreachable
474; CHECK: [[left_right]]:
475; CHECK-NEXT: %[[lr_pad:.+]] = cleanuppad within %[[left_cp]] []
476; CHECK-NEXT: unreachable
477
478root.cont:
479 call void @g() [ "funclet"(token %root.pad) ]
480 invoke void @g() [ "funclet"(token %root.pad) ]
481 to label %unreach unwind label %right
482; CHECK: [[root_cont]]:
483; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_pad]]) ]
484; CHECK-NEXT: to label %[[root_cont_cont:.+]] unwind label %cleanup
485; CHECK: [[root_cont_cont]]:
486; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_pad]]) ]
487; CHECK-NEXT: to label %[[unreach]] unwind label %[[right:.+]]
488
489right:
490 %right.pad = cleanuppad within %root.pad []
491 invoke void @g() [ "funclet"(token %right.pad) ]
492 to label %unreach unwind label %right.child
493; CHECK: [[right]]:
494; CHECK-NEXT: %[[right_pad:.+]] = cleanuppad within %[[root_pad]] []
495; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[right_pad]]) ]
496; CHECK-NEXT: to label %[[unreach]] unwind label %[[right_child:.+]]
497
498right.child:
499 %rc.pad = cleanuppad within %right.pad []
500 invoke void @g() [ "funclet"(token %rc.pad) ]
501 to label %unreach unwind label %far_right
502; CHECK: [[right_child]]:
503; CHECK-NEXT: %[[rc_pad:.+]] = cleanuppad within %[[right_pad]] []
504; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[rc_pad]]) ]
505; CHECK-NEXT: to label %[[unreach]] unwind label %[[far_right:.+]]
506
507far_right:
508 %fr.cs = catchswitch within %root.pad [label %fr.catch] unwind to caller
509; CHECK: [[far_right]]:
510; CHECK-NEXT: %[[fr_cs:.+]] = catchswitch within %[[root_pad]] [label %[[fr_catch:.+]]] unwind label %cleanup
511
512fr.catch:
513 %fr.cp = catchpad within %fr.cs []
514 unreachable
515; CHECK: [[fr_catch]]:
516; CHECK-NEXT: %[[fr_cp:.+]] = catchpad within %[[fr_cs]] []
517; CHECK-NEXT: unreachable
518
519unreach:
520 unreachable
521; CHECK: [[unreach]]:
522; CHECK-NEXT: unreachable
523
524exit:
525 ret void
526}
527
528
529;;; Test with a no-info funclet (right) which has a cousin (left.left) that
530;;; unwinds to another cousin (left.right); make sure we don't trip over this
531;;; when propagating unwind destination info to "right".
532;;; CHECK-LABEL: define void @test7(
533define void @test7() personality void()* @ProcessCLRException {
534entry:
535; CHECK-NEXT: entry:
536 invoke void @test7_inlinee()
537 to label %exit unwind label %cleanup
538cleanup:
539 %pad = cleanuppad within none []
540 call void @g() [ "funclet"(token %pad) ]
541 cleanupret from %pad unwind to caller
542exit:
543 ret void
544}
545
546define void @test7_inlinee() alwaysinline personality void ()* @ProcessCLRException {
547entry:
548 invoke void @g()
549 to label %exit unwind label %root
550; CHECK-NEXT: invoke void @g()
551; CHECK-NEXT: unwind label %[[root:.+]]
552
553root:
554 %root.cp = cleanuppad within none []
555 invoke void @g() [ "funclet"(token %root.cp) ]
556 to label %root.cont unwind label %child
557; CHECK: [[root]]:
558; CHECK-NEXT: %[[root_cp:.+]] = cleanuppad within none []
559; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_cp]]) ]
560; CHECK-NEXT: to label %[[root_cont:.+]] unwind label %[[child:.+]]
561
562root.cont:
563 cleanupret from %root.cp unwind to caller
564; CHECK: [[root_cont]]:
565; CHECK-NEXT: cleanupret from %[[root_cp]] unwind label %cleanup
566
567child:
568 %child.cp = cleanuppad within %root.cp []
569 invoke void @g() [ "funclet"(token %child.cp) ]
570 to label %child.cont unwind label %left
571; CHECK: [[child]]:
572; CHECK-NEXT: %[[child_cp:.+]] = cleanuppad within %[[root_cp]] []
573; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[child_cp]]) ]
574; CHECK-NEXT: to label %[[child_cont:.+]] unwind label %[[left:.+]]
575
576left:
577 %left.cp = cleanuppad within %child.cp []
578 invoke void @g() [ "funclet"(token %left.cp) ]
579 to label %left.cont unwind label %left.left
580; CHECK: [[left]]:
581; CHECK-NEXT: %[[left_cp:.+]] = cleanuppad within %[[child_cp]] []
582; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
583; CHECK-NEXT: to label %[[left_cont:.+]] unwind label %[[left_left:.+]]
584
585left.left:
586 %ll.cp = cleanuppad within %left.cp []
587 cleanupret from %ll.cp unwind label %left.right
588; CHECK: [[left_left]]:
589; CHECK-NEXT: %[[ll_cp:.+]] = cleanuppad within %[[left_cp]] []
590; CHECK-NEXT: cleanupret from %[[ll_cp]] unwind label %[[left_right:.+]]
591
592left.cont:
593 invoke void @g() [ "funclet"(token %left.cp) ]
594 to label %unreach unwind label %left.right
595; CHECK: [[left_cont]]:
596; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
597; CHECK-NEXT: to label %[[unreach:.+]] unwind label %[[left_right]]
598
599left.right:
600 %lr.cp = cleanuppad within %left.cp []
601 unreachable
602; CHECK: [[left_right]]:
603; CHECK-NEXT: %[[lr_cp:.+]] = cleanuppad within %[[left_cp]] []
604; CHECK-NEXT: unreachable
605
606child.cont:
607 invoke void @g() [ "funclet"(token %child.cp) ]
608 to label %unreach unwind label %right
609; CHECK: [[child_cont]]:
610; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[child_cp]]) ]
611; CHECK-NEXT: to label %[[unreach]] unwind label %[[right:.+]]
612
613right:
614 %right.cp = cleanuppad within %child.cp []
615 call void @g() [ "funclet"(token %right.cp) ]
616 unreachable
617; CHECK: [[right]]:
618; CHECK-NEXT: %[[right_cp:.+]] = cleanuppad within %[[child_cp]]
619; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[right_cp]]) ]
620; CHECK-NEXT: to label %[[right_cont:.+]] unwind label %cleanup
621; CHECK: [[right_cont]]:
622; CHECK-NEXT: unreachable
623
624unreach:
625 unreachable
626; CHECK: [[unreach]]:
627; CHECK-NEXT: unreachable
628
629exit:
630 ret void
631}
Joseph Tremouletb41632b2016-01-20 02:15:15 +0000632
633declare void @ProcessCLRException()
634
635; Make sure the logic doesn't get tripped up when the inlined invoke is
636; itself within a funclet in the caller.
Joseph Tremoulete92e0a92016-09-04 01:23:20 +0000637; CHECK-LABEL: define void @test8(
638define void @test8() personality void ()* @ProcessCLRException {
Joseph Tremouletb41632b2016-01-20 02:15:15 +0000639entry:
640 invoke void @g()
641 to label %exit unwind label %callsite_parent
642callsite_parent:
643 %callsite_parent.pad = cleanuppad within none []
644; CHECK: %callsite_parent.pad = cleanuppad within none
Joseph Tremoulete92e0a92016-09-04 01:23:20 +0000645 invoke void @test8_inlinee() [ "funclet"(token %callsite_parent.pad) ]
Joseph Tremouletb41632b2016-01-20 02:15:15 +0000646 to label %ret unwind label %cleanup
647ret:
648 cleanupret from %callsite_parent.pad unwind label %cleanup
649cleanup:
650 %pad = cleanuppad within none []
651 call void @g() [ "funclet"(token %pad) ]
652 cleanupret from %pad unwind to caller
653exit:
654 ret void
655}
656
Joseph Tremoulete92e0a92016-09-04 01:23:20 +0000657define void @test8_inlinee() alwaysinline personality void ()* @ProcessCLRException {
Joseph Tremouletb41632b2016-01-20 02:15:15 +0000658entry:
659 invoke void @g()
660 to label %exit unwind label %inlinee_cleanup
661; CHECK-NEXT: invoke void @g() [ "funclet"(token %callsite_parent.pad) ]
662; CHECK-NEXT: unwind label %[[inlinee_cleanup:.+]]
663
664inlinee_cleanup:
665 %inlinee.pad = cleanuppad within none []
666 call void @g() [ "funclet"(token %inlinee.pad) ]
667 unreachable
668; CHECK: [[inlinee_cleanup]]:
669; CHECK-NEXT: %[[inlinee_pad:[^ ]+]] = cleanuppad within %callsite_parent.pad
670; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[inlinee_pad]]) ]
671; CHECK-NEXT: unwind label %cleanup{{$}}
672
673exit:
674 ret void
675}