74 lines · c
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -enable-var-scope -check-prefixes=CHECK,X86 %s2// RUN: %clang_cc1 -triple amdgcn -emit-llvm < %s | FileCheck -enable-var-scope -check-prefixes=CHECK,AMDGCN %s3 4// CHECK: @foo ={{.*}} addrspace(1) global5int foo __attribute__((address_space(1)));6 7// CHECK: @ban ={{.*}} addrspace(1) global8int ban[10] __attribute__((address_space(1)));9 10// CHECK: @a ={{.*}} global11int a __attribute__((address_space(0)));12 13// CHECK-LABEL: define{{.*}} i32 @test1()14// CHECK: load i32, ptr addrspace(1) @foo15int test1(void) { return foo; }16 17// CHECK-LABEL: define{{.*}} i32 @test2(i32 noundef %i)18// CHECK: load i32, ptr addrspace(1)19// CHECK-NEXT: ret i3220int 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 ptr addrspace(2), ptr @B27// AMDGCN: load ptr addrspace(2), ptr addrspacecast (ptr addrspace(1) @B to ptr)28// CHECK: load i32, ptr addrspace(2)29// X86: load ptr addrspace(2), ptr @A30// AMDGCN: load ptr addrspace(2), ptr addrspacecast (ptr addrspace(1) @A to ptr)31// CHECK: store i32 {{.*}}, ptr addrspace(2)32void test3(void) {33 *A = *B;34}35 36// PR743737typedef struct {38 float aData[1];39} MyStruct;40 41// CHECK-LABEL: define{{.*}} void @test4(42// CHECK: call void @llvm.memcpy.p0.p243// CHECK: call void @llvm.memcpy.p2.p044void test4(MyStruct __attribute__((address_space(2))) *pPtr) {45 MyStruct s = pPtr[0];46 pPtr[0] = s;47}48 49// Make sure the right address space is used when doing arithmetic on a void50// pointer. Make sure no invalid bitcast is introduced.51 52// CHECK-LABEL: @void_ptr_arithmetic_test(53// X86: [[ALLOCA:%.*]] = alloca ptr addrspace(1)54// X86-NEXT: store ptr addrspace(1) %arg, ptr [[ALLOCA]]55// X86-NEXT: load ptr addrspace(1), ptr [[ALLOCA]]56// X86-NEXT: getelementptr inbounds i8, ptr addrspace(1)57// X86-NEXT: ret ptr addrspace(1)58void __attribute__((address_space(1)))*59void_ptr_arithmetic_test(void __attribute__((address_space(1))) *arg) {60 return arg + 4;61}62 63// CHECK-LABEL: define{{.*}} ptr @test5(64const unsigned *test5(void) {65 // Intentionally leave a part of an array uninitialized. This triggers a66 // different code path contrary to a fully initialized array.67 // X86: ret ptr @test5.bars68 // AMDGCN: ret ptr addrspacecast (ptr addrspace(4) @test5.bars to ptr)69 static const unsigned bars[256] = {70 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,71 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};72 return &bars[0];73}74