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