1 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s --check-prefix=CHECK-DEFINITIONS
4 // This test ensures the proper address spaces and address space cast are used
5 // for constructors, member functions and destructors.
6 // See also atexit.cl and global_init.cl for other specific tests.
8 // CHECK: %struct.MyType = type { i32, [5 x i32] }
10 MyType(int i) : i(i) {}
11 MyType(int i) __constant : i(i) {}
13 ~MyType() __constant {}
14 int bar() { return i + 2; }
15 int bar() __constant { return i + 1; }
17 int a[5] = {42, 43, 44, 45, 46};
20 // CHECK: @const1 ={{.*}} addrspace(2) global %struct.MyType zeroinitializer
21 __constant MyType const1 = 1;
22 // CHECK: @const2 ={{.*}} addrspace(2) global %struct.MyType zeroinitializer
23 __constant MyType const2(2);
24 // CHECK: @glob ={{.*}} addrspace(1) global %struct.MyType zeroinitializer
27 // CHECK: @constinit ={{.*}} addrspace(2) constant [5 x i32] [i32 42, i32 43, i32 44, i32 45, i32 46]
29 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} @const1, i32 noundef 1)
30 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} @const2, i32 noundef 2)
31 // CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), i32 noundef 1)
33 // CHECK-LABEL: define{{.*}} spir_kernel void @fooGlobal()
34 kernel void fooGlobal() {
35 // CHECK: call spir_func noundef i32 @_ZNU3AS46MyType3barEv(ptr addrspace(4) {{[^,]*}} addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)))
37 // CHECK: call spir_func noundef i32 @_ZNU3AS26MyType3barEv(ptr addrspace(2) {{[^,]*}} @const1)
39 // CHECK: call spir_func void @_ZNU3AS26MyTypeD1Ev(ptr addrspace(2) {{[^,]*}} @const1)
43 // CHECK-LABEL: define{{.*}} spir_kernel void @fooLocal()
44 kernel void fooLocal() {
45 // CHECK: [[VAR:%.*]] = alloca %struct.MyType
46 // CHECK: [[REG:%.*]] ={{.*}} addrspacecast ptr [[VAR]] to ptr addrspace(4)
47 // CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} [[REG]], i32 noundef 3)
49 // CHECK: [[REG:%.*]] ={{.*}} addrspacecast ptr [[VAR]] to ptr addrspace(4)
50 // CHECK: call spir_func noundef i32 @_ZNU3AS46MyType3barEv(ptr addrspace(4) {{[^,]*}} [[REG]])
52 // CHECK: [[REG:%.*]] ={{.*}} addrspacecast ptr [[VAR]] to ptr addrspace(4)
53 // CHECK: call spir_func void @_ZNU3AS46MyTypeD1Ev(ptr addrspace(4) {{[^,]*}} [[REG]])
56 // Ensure all members are defined for all the required address spaces.
57 // CHECK-DEFINITIONS-DAG: define linkonce_odr spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} %this, i32 noundef %i)
58 // CHECK-DEFINITIONS-DAG: define linkonce_odr spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} %this, i32 noundef %i)
59 // CHECK-DEFINITIONS-DAG: define linkonce_odr spir_func void @_ZNU3AS26MyTypeD1Ev(ptr addrspace(2) {{[^,]*}} %this)
60 // CHECK-DEFINITIONS-DAG: define linkonce_odr spir_func void @_ZNU3AS46MyTypeD1Ev(ptr addrspace(4) {{[^,]*}} %this)
61 // CHECK-DEFINITIONS-DAG: define linkonce_odr spir_func noundef i32 @_ZNU3AS26MyType3barEv(ptr addrspace(2) {{[^,]*}} %this)
62 // CHECK-DEFINITIONS-DAG: define linkonce_odr spir_func noundef i32 @_ZNU3AS46MyType3barEv(ptr addrspace(4) {{[^,]*}} %this)