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