inline-funclets.ll
24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
; RUN: opt -inline -S %s | FileCheck %s
; RUN: opt -passes='cgscc(inline)' -S %s | FileCheck %s
declare void @g()
;;; Test with a call in a funclet that needs to remain a call
;;; when inlined because the funclet doesn't unwind to caller.
;;; CHECK-LABEL: define void @test1(
define void @test1() personality void ()* @g {
entry:
; CHECK-NEXT: entry:
invoke void @test1_inlinee()
to label %exit unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test1_inlinee() alwaysinline personality void ()* @g {
entry:
invoke void @g()
to label %exit unwind label %cleanup.inner
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: unwind label %[[cleanup_inner:.+]]
cleanup.inner:
%pad.inner = cleanuppad within none []
call void @g() [ "funclet"(token %pad.inner) ]
cleanupret from %pad.inner unwind label %cleanup.outer
; CHECK: [[cleanup_inner]]:
; The call here needs to remain a call becuase pad.inner has a cleanupret
; that stays within the inlinee.
; CHECK-NEXT: %[[pad_inner:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: call void @g() [ "funclet"(token %[[pad_inner]]) ]
; CHECK-NEXT: cleanupret from %[[pad_inner]] unwind label %[[cleanup_outer:.+]]
cleanup.outer:
%pad.outer = cleanuppad within none []
call void @g() [ "funclet"(token %pad.outer) ]
cleanupret from %pad.outer unwind to caller
; CHECK: [[cleanup_outer]]:
; The call and cleanupret here need to be redirected to caller cleanup
; CHECK-NEXT: %[[pad_outer:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[pad_outer]]) ]
; CHECK-NEXT: unwind label %cleanup
; CHECK: cleanupret from %[[pad_outer]] unwind label %cleanup{{$}}
exit:
ret void
}
;;; Test with an "unwind to caller" catchswitch in a parent funclet
;;; that needs to remain "unwind to caller" because the parent
;;; doesn't unwind to caller.
;;; CHECK-LABEL: define void @test2(
define void @test2() personality void ()* @g {
entry:
; CHECK-NEXT: entry:
invoke void @test2_inlinee()
to label %exit unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test2_inlinee() alwaysinline personality void ()* @g {
entry:
invoke void @g()
to label %exit unwind label %cleanup1
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: unwind label %[[cleanup1:.+]]
cleanup1:
%outer = cleanuppad within none []
invoke void @g() [ "funclet"(token %outer) ]
to label %ret1 unwind label %catchswitch
; CHECK: [[cleanup1]]:
; CHECK-NEXT: %[[outer:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[outer]]) ]
; CHECK-NEXT: unwind label %[[catchswitch:.+]]
catchswitch:
%cs = catchswitch within %outer [label %catch] unwind to caller
; CHECK: [[catchswitch]]:
; The catchswitch here needs to remain "unwind to caller" since %outer
; has a cleanupret that remains within the inlinee.
; CHECK-NEXT: %[[cs:[^ ]+]] = catchswitch within %[[outer]] [label %[[catch:.+]]] unwind to caller
catch:
%inner = catchpad within %cs []
call void @g() [ "funclet"(token %inner) ]
catchret from %inner to label %ret1
; CHECK: [[catch]]:
; The call here needs to remain a call since it too is within %outer
; CHECK: %[[inner:[^ ]+]] = catchpad within %[[cs]]
; CHECK-NEXT: call void @g() [ "funclet"(token %[[inner]]) ]
ret1:
cleanupret from %outer unwind label %cleanup2
; CHECK: cleanupret from %[[outer]] unwind label %[[cleanup2:.+]]
cleanup2:
%later = cleanuppad within none []
cleanupret from %later unwind to caller
; CHECK: [[cleanup2]]:
; The cleanupret here needs to get redirected to the caller cleanup
; CHECK-NEXT: %[[later:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: cleanupret from %[[later]] unwind label %cleanup{{$}}
exit:
ret void
}
;;; Test with a call in a cleanup that has no definitive unwind
;;; destination, that must be rewritten to an invoke.
;;; CHECK-LABEL: define void @test3(
define void @test3() personality void ()* @g {
entry:
; CHECK-NEXT: entry:
invoke void @test3_inlinee()
to label %exit unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test3_inlinee() alwaysinline personality void ()* @g {
entry:
invoke void @g()
to label %exit unwind label %cleanup
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: unwind label %[[cleanup:.+]]
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
unreachable
; CHECK: [[cleanup]]:
; The call must be rewritten to an invoke targeting the caller cleanup
; because it may well unwind to there.
; CHECK-NEXT: %[[pad:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[pad]]) ]
; CHECK-NEXT: unwind label %cleanup{{$}}
exit:
ret void
}
;;; Test with a catchswitch in a cleanup that has no definitive
;;; unwind destination, that must be rewritten to unwind to the
;;; inlined invoke's unwind dest
;;; CHECK-LABEL: define void @test4(
define void @test4() personality void ()* @g {
entry:
; CHECK-NEXT: entry:
invoke void @test4_inlinee()
to label %exit unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test4_inlinee() alwaysinline personality void ()* @g {
entry:
invoke void @g()
to label %exit unwind label %cleanup
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: unwind label %[[cleanup:.+]]
cleanup:
%clean = cleanuppad within none []
invoke void @g() [ "funclet"(token %clean) ]
to label %unreachable unwind label %dispatch
; CHECK: [[cleanup]]:
; CHECK-NEXT: %[[clean:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[clean]]) ]
; CHECK-NEXT: unwind label %[[dispatch:.+]]
dispatch:
%cs = catchswitch within %clean [label %catch] unwind to caller
; CHECK: [[dispatch]]:
; The catchswitch must be rewritten to unwind to %cleanup in the caller
; because it may well unwind to there.
; CHECK-NEXT: %[[cs:[^ ]+]] = catchswitch within %[[clean]] [label %[[catch:.+]]] unwind label %cleanup{{$}}
catch:
catchpad within %cs []
br label %unreachable
unreachable:
unreachable
exit:
ret void
}
;;; Test with multiple levels of nesting, and unwind dests
;;; that need to be inferred from ancestors, descendants,
;;; and cousins.
;;; CHECK-LABEL: define void @test5(
define void @test5() personality void ()* @g {
entry:
; CHECK-NEXT: entry:
invoke void @test5_inlinee()
to label %exit unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test5_inlinee() alwaysinline personality void ()* @g {
entry:
invoke void @g()
to label %cont unwind label %noinfo.root
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: to label %[[cont:[^ ]+]] unwind label %[[noinfo_root:.+]]
noinfo.root:
%noinfo.root.pad = cleanuppad within none []
call void @g() [ "funclet"(token %noinfo.root.pad) ]
invoke void @g() [ "funclet"(token %noinfo.root.pad) ]
to label %noinfo.root.cont unwind label %noinfo.left
; CHECK: [[noinfo_root]]:
; Nothing under "noinfo.root" has a definitive unwind destination, so
; we must assume all of it may actually unwind, and redirect unwinds
; to the cleanup in the caller.
; CHECK-NEXT: %[[noinfo_root_pad:[^ ]+]] = cleanuppad within none []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_root_pad]]) ]
; CHECK-NEXT: to label %[[next:[^ ]+]] unwind label %cleanup{{$}}
; CHECK: [[next]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_root_pad]]) ]
; CHECK-NEXT: to label %[[noinfo_root_cont:[^ ]+]] unwind label %[[noinfo_left:.+]]
noinfo.left:
%noinfo.left.pad = cleanuppad within %noinfo.root.pad []
invoke void @g() [ "funclet"(token %noinfo.left.pad) ]
to label %unreachable unwind label %noinfo.left.child
; CHECK: [[noinfo_left]]:
; CHECK-NEXT: %[[noinfo_left_pad:[^ ]+]] = cleanuppad within %[[noinfo_root_pad]]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_left_pad]]) ]
; CHECK-NEXT: unwind label %[[noinfo_left_child:.+]]
noinfo.left.child:
%noinfo.left.child.cs = catchswitch within %noinfo.left.pad [label %noinfo.left.child.catch] unwind to caller
; CHECK: [[noinfo_left_child]]:
; CHECK-NEXT: %[[noinfo_left_child_cs:[^ ]+]] = catchswitch within %[[noinfo_left_pad]] [label %[[noinfo_left_child_catch:[^ ]+]]] unwind label %cleanup{{$}}
noinfo.left.child.catch:
%noinfo.left.child.pad = catchpad within %noinfo.left.child.cs []
call void @g() [ "funclet"(token %noinfo.left.child.pad) ]
br label %unreachable
; CHECK: [[noinfo_left_child_catch]]:
; CHECK-NEXT: %[[noinfo_left_child_pad:[^ ]+]] = catchpad within %[[noinfo_left_child_cs]] []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_left_child_pad]]) ]
; CHECK-NEXT: unwind label %cleanup{{$}}
noinfo.root.cont:
invoke void @g() [ "funclet"(token %noinfo.root.pad) ]
to label %unreachable unwind label %noinfo.right
; CHECK: [[noinfo_root_cont]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_root_pad]]) ]
; CHECK-NEXT: unwind label %[[noinfo_right:.+]]
noinfo.right:
%noinfo.right.cs = catchswitch within %noinfo.root.pad [label %noinfo.right.catch] unwind to caller
; CHECK: [[noinfo_right]]:
; CHECK-NEXT: %[[noinfo_right_cs:[^ ]+]] = catchswitch within %[[noinfo_root_pad]] [label %[[noinfo_right_catch:[^ ]+]]] unwind label %cleanup{{$}}
noinfo.right.catch:
%noinfo.right.pad = catchpad within %noinfo.right.cs []
invoke void @g() [ "funclet"(token %noinfo.right.pad) ]
to label %unreachable unwind label %noinfo.right.child
; CHECK: [[noinfo_right_catch]]:
; CHECK-NEXT: %[[noinfo_right_pad:[^ ]+]] = catchpad within %[[noinfo_right_cs]]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_right_pad]]) ]
; CHECK-NEXT: unwind label %[[noinfo_right_child:.+]]
noinfo.right.child:
%noinfo.right.child.pad = cleanuppad within %noinfo.right.pad []
call void @g() [ "funclet"(token %noinfo.right.child.pad) ]
br label %unreachable
; CHECK: [[noinfo_right_child]]:
; CHECK-NEXT: %[[noinfo_right_child_pad:[^ ]+]] = cleanuppad within %[[noinfo_right_pad]]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[noinfo_right_child_pad]]) ]
; CHECK-NEXT: unwind label %cleanup{{$}}
cont:
invoke void @g()
to label %exit unwind label %implicit.root
; CHECK: [[cont]]:
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: unwind label %[[implicit_root:.+]]
implicit.root:
%implicit.root.pad = cleanuppad within none []
call void @g() [ "funclet"(token %implicit.root.pad) ]
invoke void @g() [ "funclet"(token %implicit.root.pad) ]
to label %implicit.root.cont unwind label %implicit.left
; CHECK: [[implicit_root]]:
; There's an unwind edge to %internal in implicit.right, and we need to propagate that
; fact down to implicit.right.grandchild, up to implicit.root, and down to
; implicit.left.child.catch, leaving all calls and "unwind to caller" catchswitches
; alone to so they don't conflict with the unwind edge in implicit.right
; CHECK-NEXT: %[[implicit_root_pad:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: call void @g() [ "funclet"(token %[[implicit_root_pad]]) ]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_root_pad]]) ]
; CHECK-NEXT: to label %[[implicit_root_cont:[^ ]+]] unwind label %[[implicit_left:.+]]
implicit.left:
%implicit.left.pad = cleanuppad within %implicit.root.pad []
invoke void @g() [ "funclet"(token %implicit.left.pad) ]
to label %unreachable unwind label %implicit.left.child
; CHECK: [[implicit_left]]:
; CHECK-NEXT: %[[implicit_left_pad:[^ ]+]] = cleanuppad within %[[implicit_root_pad:[^ ]+]]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_left_pad]]) ]
; CHECK-NEXT: unwind label %[[implicit_left_child:.+]]
implicit.left.child:
%implicit.left.child.cs = catchswitch within %implicit.left.pad [label %implicit.left.child.catch] unwind to caller
; CHECK: [[implicit_left_child]]:
; CHECK-NEXT: %[[implicit_left_child_cs:[^ ]+]] = catchswitch within %[[implicit_left_pad]] [label %[[implicit_left_child_catch:[^ ]+]]] unwind to caller
implicit.left.child.catch:
%implicit.left.child.pad = catchpad within %implicit.left.child.cs []
call void @g() [ "funclet"(token %implicit.left.child.pad) ]
br label %unreachable
; CHECK: [[implicit_left_child_catch]]:
; CHECK-NEXT: %[[implicit_left_child_pad:[^ ]+]] = catchpad within %[[implicit_left_child_cs]]
; CHECK-NEXT: call void @g() [ "funclet"(token %[[implicit_left_child_pad]]) ]
implicit.root.cont:
invoke void @g() [ "funclet"(token %implicit.root.pad) ]
to label %unreachable unwind label %implicit.right
; CHECK: [[implicit_root_cont]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_root_pad]]) ]
; CHECK-NEXT: unwind label %[[implicit_right:.+]]
implicit.right:
%implicit.right.cs = catchswitch within %implicit.root.pad [label %implicit.right.catch] unwind label %internal
; CHECK: [[implicit_right]]:
; This is the unwind edge (to %internal) whose existence needs to get propagated around the "implicit" tree
; CHECK-NEXT: %[[implicit_right_cs:[^ ]+]] = catchswitch within %[[implicit_root_pad]] [label %[[implicit_right_catch:[^ ]+]]] unwind label %[[internal:.+]]
implicit.right.catch:
%implicit.right.pad = catchpad within %implicit.right.cs []
invoke void @g() [ "funclet"(token %implicit.right.pad) ]
to label %unreachable unwind label %implicit.right.child
; CHECK: [[implicit_right_catch]]:
; CHECK-NEXT: %[[implicit_right_pad:[^ ]+]] = catchpad within %[[implicit_right_cs]]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_right_pad]]) ]
; CHECK-NEXT: unwind label %[[implicit_right_child:.+]]
implicit.right.child:
%implicit.right.child.pad = cleanuppad within %implicit.right.pad []
invoke void @g() [ "funclet"(token %implicit.right.child.pad) ]
to label %unreachable unwind label %implicit.right.grandchild
; CHECK: [[implicit_right_child]]:
; CHECK-NEXT: %[[implicit_right_child_pad:[^ ]+]] = cleanuppad within %[[implicit_right_pad]]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[implicit_right_child_pad]]) ]
; CHECK-NEXT: unwind label %[[implicit_right_grandchild:.+]]
implicit.right.grandchild:
%implicit.right.grandchild.cs = catchswitch within %implicit.right.child.pad [label %implicit.right.grandchild.catch] unwind to caller
; CHECK: [[implicit_right_grandchild]]:
; CHECK-NEXT: %[[implicit_right_grandchild_cs:[^ ]+]] = catchswitch within %[[implicit_right_child_pad]] [label %[[implicit_right_grandchild_catch:[^ ]+]]] unwind to caller
implicit.right.grandchild.catch:
%implicit.right.grandhcild.pad = catchpad within %implicit.right.grandchild.cs []
call void @g() [ "funclet"(token %implicit.right.grandhcild.pad) ]
br label %unreachable
; CHECK: [[implicit_right_grandchild_catch]]:
; CHECK-NEXT: %[[implicit_right_grandhcild_pad:[^ ]+]] = catchpad within %[[implicit_right_grandchild_cs]]
; CHECK-NEXT: call void @g() [ "funclet"(token %[[implicit_right_grandhcild_pad]]) ]
internal:
%internal.pad = cleanuppad within none []
call void @g() [ "funclet"(token %internal.pad) ]
cleanupret from %internal.pad unwind to caller
; CHECK: [[internal]]:
; internal is a cleanup with a "return to caller" cleanuppad; that needs to get redirected
; to %cleanup in the caller, and the call needs to get similarly rewritten to an invoke.
; CHECK-NEXT: %[[internal_pad:[^ ]+]] = cleanuppad within none
; CHECK-NEXT: invoke void @g() [ "funclet"(token %internal.pad.i) ]
; CHECK-NEXT: to label %[[next:[^ ]+]] unwind label %cleanup{{$}}
; CHECK: [[next]]:
; CHECK-NEXT: cleanupret from %[[internal_pad]] unwind label %cleanup{{$}}
unreachable:
unreachable
exit:
ret void
}
;;; Test with funclets that don't have information for themselves, but have
;;; descendants which unwind to other descendants (left.left unwinds to
;;; left.right, and right unwinds to far_right). Make sure that these local
;;; unwinds don't trip up processing of the ancestor nodes (left and root) that
;;; ultimately have no information.
;;; CHECK-LABEL: define void @test6(
define void @test6() personality void()* @ProcessCLRException {
entry:
; CHECK-NEXT: entry:
invoke void @test6_inlinee()
to label %exit unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test6_inlinee() alwaysinline personality void ()* @ProcessCLRException {
entry:
invoke void @g()
to label %exit unwind label %root
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: unwind label %[[root:.+]]
root:
%root.pad = cleanuppad within none []
invoke void @g() [ "funclet"(token %root.pad) ]
to label %root.cont unwind label %left
; CHECK: [[root]]:
; CHECK-NEXT: %[[root_pad:.+]] = cleanuppad within none []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_pad]]) ]
; CHECK-NEXT: to label %[[root_cont:.+]] unwind label %[[left:.+]]
left:
%left.cs = catchswitch within %root.pad [label %left.catch] unwind to caller
; CHECK: [[left]]:
; CHECK-NEXT: %[[left_cs:.+]] = catchswitch within %[[root_pad]] [label %[[left_catch:.+]]] unwind label %cleanup
left.catch:
%left.cp = catchpad within %left.cs []
call void @g() [ "funclet"(token %left.cp) ]
invoke void @g() [ "funclet"(token %left.cp) ]
to label %unreach unwind label %left.left
; CHECK: [[left_catch:.+]]:
; CHECK-NEXT: %[[left_cp:.+]] = catchpad within %[[left_cs]] []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
; CHECK-NEXT: to label %[[lc_cont:.+]] unwind label %cleanup
; CHECK: [[lc_cont]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
; CHECK-NEXT: to label %[[unreach:.+]] unwind label %[[left_left:.+]]
left.left:
%ll.pad = cleanuppad within %left.cp []
cleanupret from %ll.pad unwind label %left.right
; CHECK: [[left_left]]:
; CHECK-NEXT: %[[ll_pad:.+]] = cleanuppad within %[[left_cp]] []
; CHECK-NEXT: cleanupret from %[[ll_pad]] unwind label %[[left_right:.+]]
left.right:
%lr.pad = cleanuppad within %left.cp []
unreachable
; CHECK: [[left_right]]:
; CHECK-NEXT: %[[lr_pad:.+]] = cleanuppad within %[[left_cp]] []
; CHECK-NEXT: unreachable
root.cont:
call void @g() [ "funclet"(token %root.pad) ]
invoke void @g() [ "funclet"(token %root.pad) ]
to label %unreach unwind label %right
; CHECK: [[root_cont]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_pad]]) ]
; CHECK-NEXT: to label %[[root_cont_cont:.+]] unwind label %cleanup
; CHECK: [[root_cont_cont]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_pad]]) ]
; CHECK-NEXT: to label %[[unreach]] unwind label %[[right:.+]]
right:
%right.pad = cleanuppad within %root.pad []
invoke void @g() [ "funclet"(token %right.pad) ]
to label %unreach unwind label %right.child
; CHECK: [[right]]:
; CHECK-NEXT: %[[right_pad:.+]] = cleanuppad within %[[root_pad]] []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[right_pad]]) ]
; CHECK-NEXT: to label %[[unreach]] unwind label %[[right_child:.+]]
right.child:
%rc.pad = cleanuppad within %right.pad []
invoke void @g() [ "funclet"(token %rc.pad) ]
to label %unreach unwind label %far_right
; CHECK: [[right_child]]:
; CHECK-NEXT: %[[rc_pad:.+]] = cleanuppad within %[[right_pad]] []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[rc_pad]]) ]
; CHECK-NEXT: to label %[[unreach]] unwind label %[[far_right:.+]]
far_right:
%fr.cs = catchswitch within %root.pad [label %fr.catch] unwind to caller
; CHECK: [[far_right]]:
; CHECK-NEXT: %[[fr_cs:.+]] = catchswitch within %[[root_pad]] [label %[[fr_catch:.+]]] unwind label %cleanup
fr.catch:
%fr.cp = catchpad within %fr.cs []
unreachable
; CHECK: [[fr_catch]]:
; CHECK-NEXT: %[[fr_cp:.+]] = catchpad within %[[fr_cs]] []
; CHECK-NEXT: unreachable
unreach:
unreachable
; CHECK: [[unreach]]:
; CHECK-NEXT: unreachable
exit:
ret void
}
;;; Test with a no-info funclet (right) which has a cousin (left.left) that
;;; unwinds to another cousin (left.right); make sure we don't trip over this
;;; when propagating unwind destination info to "right".
;;; CHECK-LABEL: define void @test7(
define void @test7() personality void()* @ProcessCLRException {
entry:
; CHECK-NEXT: entry:
invoke void @test7_inlinee()
to label %exit unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test7_inlinee() alwaysinline personality void ()* @ProcessCLRException {
entry:
invoke void @g()
to label %exit unwind label %root
; CHECK-NEXT: invoke void @g()
; CHECK-NEXT: unwind label %[[root:.+]]
root:
%root.cp = cleanuppad within none []
invoke void @g() [ "funclet"(token %root.cp) ]
to label %root.cont unwind label %child
; CHECK: [[root]]:
; CHECK-NEXT: %[[root_cp:.+]] = cleanuppad within none []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[root_cp]]) ]
; CHECK-NEXT: to label %[[root_cont:.+]] unwind label %[[child:.+]]
root.cont:
cleanupret from %root.cp unwind to caller
; CHECK: [[root_cont]]:
; CHECK-NEXT: cleanupret from %[[root_cp]] unwind label %cleanup
child:
%child.cp = cleanuppad within %root.cp []
invoke void @g() [ "funclet"(token %child.cp) ]
to label %child.cont unwind label %left
; CHECK: [[child]]:
; CHECK-NEXT: %[[child_cp:.+]] = cleanuppad within %[[root_cp]] []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[child_cp]]) ]
; CHECK-NEXT: to label %[[child_cont:.+]] unwind label %[[left:.+]]
left:
%left.cp = cleanuppad within %child.cp []
invoke void @g() [ "funclet"(token %left.cp) ]
to label %left.cont unwind label %left.left
; CHECK: [[left]]:
; CHECK-NEXT: %[[left_cp:.+]] = cleanuppad within %[[child_cp]] []
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
; CHECK-NEXT: to label %[[left_cont:.+]] unwind label %[[left_left:.+]]
left.left:
%ll.cp = cleanuppad within %left.cp []
cleanupret from %ll.cp unwind label %left.right
; CHECK: [[left_left]]:
; CHECK-NEXT: %[[ll_cp:.+]] = cleanuppad within %[[left_cp]] []
; CHECK-NEXT: cleanupret from %[[ll_cp]] unwind label %[[left_right:.+]]
left.cont:
invoke void @g() [ "funclet"(token %left.cp) ]
to label %unreach unwind label %left.right
; CHECK: [[left_cont]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[left_cp]]) ]
; CHECK-NEXT: to label %[[unreach:.+]] unwind label %[[left_right]]
left.right:
%lr.cp = cleanuppad within %left.cp []
unreachable
; CHECK: [[left_right]]:
; CHECK-NEXT: %[[lr_cp:.+]] = cleanuppad within %[[left_cp]] []
; CHECK-NEXT: unreachable
child.cont:
invoke void @g() [ "funclet"(token %child.cp) ]
to label %unreach unwind label %right
; CHECK: [[child_cont]]:
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[child_cp]]) ]
; CHECK-NEXT: to label %[[unreach]] unwind label %[[right:.+]]
right:
%right.cp = cleanuppad within %child.cp []
call void @g() [ "funclet"(token %right.cp) ]
unreachable
; CHECK: [[right]]:
; CHECK-NEXT: %[[right_cp:.+]] = cleanuppad within %[[child_cp]]
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[right_cp]]) ]
; CHECK-NEXT: to label %[[right_cont:.+]] unwind label %cleanup
; CHECK: [[right_cont]]:
; CHECK-NEXT: unreachable
unreach:
unreachable
; CHECK: [[unreach]]:
; CHECK-NEXT: unreachable
exit:
ret void
}
declare void @ProcessCLRException()
; Make sure the logic doesn't get tripped up when the inlined invoke is
; itself within a funclet in the caller.
; CHECK-LABEL: define void @test8(
define void @test8() personality void ()* @ProcessCLRException {
entry:
invoke void @g()
to label %exit unwind label %callsite_parent
callsite_parent:
%callsite_parent.pad = cleanuppad within none []
; CHECK: %callsite_parent.pad = cleanuppad within none
invoke void @test8_inlinee() [ "funclet"(token %callsite_parent.pad) ]
to label %ret unwind label %cleanup
ret:
cleanupret from %callsite_parent.pad unwind label %cleanup
cleanup:
%pad = cleanuppad within none []
call void @g() [ "funclet"(token %pad) ]
cleanupret from %pad unwind to caller
exit:
ret void
}
define void @test8_inlinee() alwaysinline personality void ()* @ProcessCLRException {
entry:
invoke void @g()
to label %exit unwind label %inlinee_cleanup
; CHECK-NEXT: invoke void @g() [ "funclet"(token %callsite_parent.pad) ]
; CHECK-NEXT: unwind label %[[inlinee_cleanup:.+]]
inlinee_cleanup:
%inlinee.pad = cleanuppad within none []
call void @g() [ "funclet"(token %inlinee.pad) ]
unreachable
; CHECK: [[inlinee_cleanup]]:
; CHECK-NEXT: %[[inlinee_pad:[^ ]+]] = cleanuppad within %callsite_parent.pad
; CHECK-NEXT: invoke void @g() [ "funclet"(token %[[inlinee_pad]]) ]
; CHECK-NEXT: unwind label %cleanup{{$}}
exit:
ret void
}