Clang Project

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