1; RUN: not opt -S %s -verify 2>&1 | FileCheck %s
2
3; CHECK: Indirect label missing from arglist.
4; CHECK-NEXT: #test1
5define void @test1() {
6  ; The %4 in the indirect label list is not found in the blockaddresses in the
7  ; arg list (bad).
8  callbr void asm sideeffect "#test1", "X,X"(i8* blockaddress(@test1, %3), i8* blockaddress(@test1, %2))
9  to label %1 [label %4, label %2]
101:
11  ret void
122:
13  ret void
143:
15  ret void
164:
17  ret void
18}
19
20; CHECK-NOT: Indirect label missing from arglist.
21define void @test2() {
22  ; %4 and %2 are both in the indirect label list and the arg list (good).
23  callbr void asm sideeffect "${0:l} ${1:l}", "X,X"(i8* blockaddress(@test2, %4), i8* blockaddress(@test2, %2))
24  to label %1 [label %4, label %2]
251:
26  ret void
272:
28  ret void
293:
30  ret void
314:
32  ret void
33}
34
35; CHECK-NOT: Indirect label missing from arglist.
36define void @test3() {
37  ; note %2 blockaddress. Such a case is possible when passing the address of
38  ; a label as an input to the inline asm (both address of label and asm goto
39  ; use blockaddress constants; we're testing that the indirect label list from
40  ; the asm goto is in the arg list to the asm).
41  callbr void asm sideeffect "${0:l} ${1:l} ${2:l}", "X,X,X"(i8* blockaddress(@test3, %4), i8* blockaddress(@test3, %2), i8* blockaddress(@test3, %3))
42  to label %1 [label %3, label %4]
431:
44  ret void
452:
46  ret void
473:
48  ret void
494:
50  ret void
51}
52
53;; Ensure you cannot use the return value of a callbr in indirect targets.
54; CHECK: Instruction does not dominate all uses!
55; CHECK-NEXT: #test4
56define i32 @test4(i1 %var) {
57entry:
58  %ret = callbr i32 asm sideeffect "#test4", "=r,X"(i8* blockaddress(@test4, %abnormal)) to label %normal [label %abnormal]
59
60normal:
61  ret i32 0
62
63abnormal:
64  ret i32 %ret
65}
66
67;; Ensure you cannot specify the same label as both normal and indirect targets.
68; CHECK: Duplicate callbr destination!
69; CHECK-NEXT: #test5
70define i32 @test5() {
71entry:
72  %ret = callbr i32 asm sideeffect "#test5", "=r,X"(i8* blockaddress(@test5, %both)) to label %both [label %both]
73
74both:
75  ret i32 0
76}
77