1 ; RUN: rm -rf %t && split-file %s %t
2 ; RUN: llvm-as %t/global-use-good.ll -o - | llvm-dis -o /dev/null
3 ; RUN: not llvm-as %t/global-use-bad.ll -o /dev/null 2>&1 | FileCheck %t/global-use-bad.ll
4 ; RUN: llvm-as %t/global-fwddecl-good.ll -o - | llvm-dis -o /dev/null
5 ; RUN: not llvm-as %t/global-fwddecl-bad.ll -o /dev/null 2>&1 | FileCheck %t/global-fwddecl-bad.ll
6 ; RUN: llvm-as %t/return-fwddecl-good.ll -o - | llvm-dis -o /dev/null
7 ; RUN: not llvm-as %t/return-fwddecl-bad.ll -o /dev/null 2>&1 | FileCheck %t/return-fwddecl-bad.ll
8 ; RUN: llvm-as %t/return-self-good.ll -o - | llvm-dis -o /dev/null
9 ; RUN: not llvm-as %t/return-self-bad.ll -o /dev/null 2>&1 | FileCheck %t/return-self-bad.ll
10 ; RUN: not llvm-as %t/return-self-bad-2.ll -o /dev/null 2>&1 | FileCheck %t/return-self-bad-2.ll
11 ; RUN: not llvm-as %t/return-unknown-fn-bad.ll -o /dev/null 2>&1 | FileCheck %t/return-unknown-fn-bad.ll
12 ; RUN: llvm-as %t/call-fwddecl-good.ll -o - | llvm-dis -o /dev/null
13 ; RUN: not llvm-as %t/call-fwddecl-bad.ll -o /dev/null 2>&1 | FileCheck %t/call-fwddecl-bad.ll
14 ; RUN: llvm-as %t/phi-good.ll -o - | llvm-dis -o /dev/null
15 ; RUN: not llvm-as %t/phi-bad.ll -o /dev/null 2>&1 | FileCheck %t/phi-bad.ll
16 ; RUN: llvm-as %t/fwddecl-phi-good.ll -o - | llvm-dis -o /dev/null
17 ; RUN: not llvm-as %t/fwddecl-phi-bad.ll -o /dev/null 2>&1 | FileCheck %t/fwddecl-phi-bad.ll
18 ; RUN: not llvm-as %t/bad-type-not-ptr.ll -o /dev/null 2>&1 | FileCheck %t/bad-type-not-ptr.ll
19 ; RUN: not llvm-as %t/bad-type-not-i8-ptr.ll -o /dev/null 2>&1 | FileCheck %t/bad-type-not-i8-ptr.ll
22 ;--- global-use-good.ll
23 target datalayout = "P2"
24 define void @fn_in_prog_as_implicit() {
29 define void @fn_in_prog_as_explicit() addrspace(2) {
34 define void @fn_in_other_as() addrspace(1) {
39 @global1 = constant i8 addrspace(2)* blockaddress(@fn_in_prog_as_implicit, %bb)
40 @global2 = constant i8 addrspace(2)* blockaddress(@fn_in_prog_as_explicit, %bb)
41 @global3 = constant i8 addrspace(1)* blockaddress(@fn_in_other_as, %bb)
43 ;--- global-use-bad.ll
44 define void @fn() addrspace(1) {
49 @global1 = constant i8 addrspace(2)* blockaddress(@fn, %bb)
50 ; CHECK: [[#@LINE-1]]:38: error: constant expression type mismatch: got type 'i8 addrspace(1)*' but expected 'i8 addrspace(2)*'
52 ; Check that a global blockaddress of a forward-declared function
53 ; uses the type of the global variable address space for the forward declaration
54 ;--- global-fwddecl-good.ll
55 @global = constant i8 addrspace(2)* blockaddress(@fwddecl_in_prog_as, %bb)
56 define void @fwddecl_in_prog_as() addrspace(2) {
62 ;--- global-fwddecl-bad.ll
63 ; This forward declaration does not match the actual function type so we should get an error:
64 @global = constant i8 addrspace(2)* blockaddress(@fwddecl_in_unexpected_as, %bb)
65 ; CHECK: [[#@LINE-1]]:77: error: 'bb' defined with type 'i8 addrspace(1)*' but expected 'i8 addrspace(2)*'
66 define void @fwddecl_in_unexpected_as() addrspace(1) {
73 ; When returning blockaddresses of forward-declared functions we
74 ; can also use the type of the variable.
75 ;--- return-fwddecl-good.ll
76 define i8 addrspace(2)* @take_as2() {
77 ret i8 addrspace(2)* blockaddress(@fwddecl_as2, %bb)
79 define i8 addrspace(1)* @take_as1() {
80 ret i8 addrspace(1)* blockaddress(@fwddecl_as1, %bb)
82 define void @fwddecl_as1() addrspace(1) {
87 define void @fwddecl_as2() addrspace(2) {
93 ;--- return-fwddecl-bad.ll
94 define i8 addrspace(2)* @take_bad() {
95 ret i8 addrspace(2)* blockaddress(@fwddecl_as1, %bb)
96 ; CHECK: [[#@LINE-1]]:51: error: 'bb' defined with type 'i8 addrspace(1)*' but expected 'i8 addrspace(2)*'
98 define void @fwddecl_as1() addrspace(1) {
104 ;--- return-self-good.ll
105 target datalayout = "P2"
106 define i8 addrspace(0)* @take_self_as0() addrspace(0) {
110 ret i8 addrspace(0)* blockaddress(@take_self_as0, %L3)
114 define i8 addrspace(2)* @take_self_prog_as() {
118 ret i8 addrspace(2)* blockaddress(@take_self_prog_as, %L3)
122 define i8 addrspace(1)* @take_self_as1() addrspace(1) {
126 ret i8 addrspace(1)* blockaddress(@take_self_as1, %L3)
130 define i8 addrspace(2)* @take_self_as2() addrspace(2) {
134 ret i8 addrspace(2)* blockaddress(@take_self_as2, %L3)
139 ;--- return-self-bad.ll
140 target datalayout = "P2"
141 define i8 addrspace(2)* @take_self_bad() addrspace(1) {
145 ret i8 addrspace(2)* blockaddress(@take_self_bad, %L3)
146 ; CHECK: [[#@LINE-1]]:24: error: constant expression type mismatch: got type 'i8 addrspace(1)*' but expected 'i8 addrspace(2)*'
150 ;--- return-self-bad-2.ll
151 target datalayout = "P2"
152 define i8* @take_self_bad_prog_as() {
156 ret i8* blockaddress(@take_self_bad_prog_as, %L3)
157 ; CHECK: [[#@LINE-1]]:11: error: constant expression type mismatch: got type 'i8 addrspace(2)*' but expected 'i8*'
162 ;--- return-unknown-fn-bad.ll
163 target datalayout = "P2"
164 define i8 addrspace(1)* @return_unknown_fn() addrspace(1) {
165 ret i8 addrspace(1)* blockaddress(@undefined, %bb)
166 ; CHECK: [[#@LINE-1]]:37: error: expected function name in blockaddress
170 ;--- call-fwddecl-good.ll
171 target datalayout = "P2"
172 define void @call_from_fn_in_as2() addrspace(2) {
173 call addrspace(2) void bitcast (i8 addrspace(2)* blockaddress(@fwddecl_as2, %bb) to void () addrspace(2)*)()
176 define void @call_from_fn_in_as1() addrspace(1) {
177 call addrspace(1) void bitcast (i8 addrspace(1)* blockaddress(@fwddecl_as1, %bb) to void () addrspace(1)*)()
180 define void @fwddecl_as2() addrspace(2) {
185 define void @fwddecl_as1() addrspace(1) {
191 ;--- call-fwddecl-bad.ll
192 target datalayout = "P2"
193 define void @call_from_fn_in_as2_explicit() addrspace(2) {
194 call addrspace(2) void bitcast (i8 addrspace(2)* blockaddress(@fwddecl_as1, %bb) to void () addrspace(2)*)()
195 ; CHECK: [[#@LINE-1]]:79: error: 'bb' defined with type 'i8 addrspace(1)*' but expected 'i8 addrspace(2)*'
198 define void @fwddecl_as1() addrspace(1) {
205 target datalayout = "P2"
206 define i8 addrspace(1)* @f1() addrspace(1) {
212 %p = phi i8 addrspace(1)* [ blockaddress(@f1, %L4), %L2 ], [ null, %L1 ]
213 ret i8 addrspace(1)* %p
217 define i8 addrspace(2)* @f2() {
223 %p = phi i8 addrspace(2)* [ blockaddress(@f2, %L4), %L2 ], [ null, %L1 ]
224 ret i8 addrspace(2)* %p
230 target datalayout = "P2"
237 %p = phi i8* [ blockaddress(@f, %L4), %L2 ], [ null, %L1 ]
238 ; CHECK: [[#@LINE-1]]:18: error: constant expression type mismatch: got type 'i8 addrspace(2)*' but expected 'i8*'
242 ; A blockaddress function forward-declaration used in a phi node should
243 ; create the forward declaration in the same address space as the current function
244 ;--- fwddecl-phi-good.ll
245 define i8 addrspace(1)* @f() addrspace(1) {
251 %p = phi i8 addrspace(1)* [ blockaddress(@fwddecl_as1, %bb), %L2 ], [ null, %L1 ]
252 ret i8 addrspace(1)* %p
256 define void @fwddecl_as1() addrspace(1) {
262 ;--- fwddecl-phi-bad.ll
263 define i8 addrspace(2)* @f() addrspace(2) {
269 %p = phi i8 addrspace(2)* [ blockaddress(@fwddecl_as1, %bb), %L2 ], [ null, %L1 ]
270 ; CHECK: [[#@LINE-1]]:58: error: 'bb' defined with type 'i8 addrspace(1)*' but expected 'i8 addrspace(2)*'
271 ret i8 addrspace(2)* %p
275 define void @fwddecl_as1() addrspace(1) {
281 ;--- bad-type-not-ptr.ll
282 @global = constant i8 blockaddress(@unknown_fn, %bb)
283 ; CHECK: [[#@LINE-1]]:23: error: type of blockaddress must be a pointer and not 'i8'
284 ;--- bad-type-not-i8-ptr.ll
285 @global = constant i32* blockaddress(@unknown_fn, %bb)
286 ; CHECK: [[#@LINE-1]]:25: error: constant expression type mismatch: got type 'i8*' but expected 'i32*'