blob: 04f88dc20a1a46dc1a88bf085ff320743a350209 [file] [log] [blame]
Chris Lattner30432fe2010-07-08 00:05:45 +00001// RUN: %clang_cc1 -emit-llvm < %s | FileCheck %s
Daniel Dunbara5728872009-12-15 20:14:24 +00002// RUN: %clang_cc1 -emit-llvm < %s | grep 'load.*addrspace(2).. @A'
3// RUN: %clang_cc1 -emit-llvm < %s | grep 'load.*addrspace(2).. @B'
Chris Lattnerfca0ddd2008-06-26 06:27:57 +00004
Chris Lattner30432fe2010-07-08 00:05:45 +00005
6// CHECK: @foo = common addrspace(1) global
Christopher Lambebb97e92008-02-04 02:31:56 +00007int foo __attribute__((address_space(1)));
Chris Lattner30432fe2010-07-08 00:05:45 +00008
9// CHECK: @ban = common addrspace(1) global
Christopher Lambebb97e92008-02-04 02:31:56 +000010int ban[10] __attribute__((address_space(1)));
11
Chris Lattner30432fe2010-07-08 00:05:45 +000012// CHECK: define i32 @test1()
13// CHECK: load i32 addrspace(1)* @foo
14int test1() { return foo; }
Christopher Lambebb97e92008-02-04 02:31:56 +000015
Chris Lattner30432fe2010-07-08 00:05:45 +000016// CHECK: define i32 @test2(i32 %i)
17// CHECK: load i32 addrspace(1)*
18// CHECK-NEXT: ret i32
19int test2(int i) { return ban[i]; }
Chris Lattnerfca0ddd2008-06-26 06:27:57 +000020
21// Both A and B point into addrspace(2).
22__attribute__((address_space(2))) int *A, *B;
23
Chris Lattner30432fe2010-07-08 00:05:45 +000024// CHECK: 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)*
Chris Lattnerfca0ddd2008-06-26 06:27:57 +000029void test3() {
30 *A = *B;
31}
32
Chris Lattner098432c2010-07-08 00:07:45 +000033// PR7437
34typedef struct {
35 float aData[1];
36} MyStruct;
37
38// CHECK: define void @test4(
Chris Lattner29457ff2010-07-08 00:23:21 +000039// CHECK: call void @llvm.memcpy.p0i8.p2i8
40// CHECK: call void @llvm.memcpy.p2i8.p0i8
Chris Lattner098432c2010-07-08 00:07:45 +000041void test4(MyStruct __attribute__((address_space(2))) *pPtr) {
42 MyStruct s = pPtr[0];
43 pPtr[0] = s;
44}