1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -check-prefixes=CHECK,GIZ %s
2 // RUN: %clang_cc1 -triple amdgcn -emit-llvm < %s | FileCheck -check-prefixes=CHECK,PIZ %s
3 // RUN: %clang_cc1 -triple amdgcn---amdgiz -emit-llvm < %s | FileCheck -check-prefixes=CHECK,GIZ %s
4 
5 // CHECK: @foo = common addrspace(1) global
6 int foo __attribute__((address_space(1)));
7 
8 // CHECK: @ban = common addrspace(1) global
9 int ban[10] __attribute__((address_space(1)));
10 
11 // CHECK: @a = common global
12 int a __attribute__((address_space(0)));
13 
14 // CHECK-LABEL: define i32 @test1()
15 // CHECK: load i32, i32 addrspace(1)* @foo
16 int test1() { return foo; }
17 
18 // CHECK-LABEL: define i32 @test2(i32 %i)
19 // CHECK: load i32, i32 addrspace(1)*
20 // CHECK-NEXT: ret i32
21 int test2(int i) { return ban[i]; }
22 
23 // Both A and B point into addrspace(2).
24 __attribute__((address_space(2))) int *A, *B;
25 
26 // CHECK-LABEL: define void @test3()
27 // GIZ: load i32 addrspace(2)*, i32 addrspace(2)** @B
28 // PIZ: load i32 addrspace(2)*, i32 addrspace(2)* addrspace(4)* @B
29 // CHECK: load i32, i32 addrspace(2)*
30 // GIZ: load i32 addrspace(2)*, i32 addrspace(2)** @A
31 // PIZ: load i32 addrspace(2)*, i32 addrspace(2)* addrspace(4)* @A
32 // CHECK: store i32 {{.*}}, i32 addrspace(2)*
33 void test3() {
34   *A = *B;
35 }
36 
37 // PR7437
38 typedef struct {
39   float aData[1];
40 } MyStruct;
41 
42 // CHECK-LABEL: define void @test4(
43 // GIZ: call void @llvm.memcpy.p0i8.p2i8
44 // GIZ: call void @llvm.memcpy.p2i8.p0i8
45 // PIZ: call void @llvm.memcpy.p4i8.p2i8
46 // PIZ: call void @llvm.memcpy.p2i8.p4i8
47 void test4(MyStruct __attribute__((address_space(2))) *pPtr) {
48   MyStruct s = pPtr[0];
49   pPtr[0] = s;
50 }
51