2019-07-25 19:04:29 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -emit-llvm -pedantic -verify -O0 -o - -DDECL | FileCheck %s --check-prefixes="COMMON,EXPL"
|
|
|
|
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -emit-llvm -pedantic -verify -O0 -o - -DDECL -DUSE_DEFLT | FileCheck %s --check-prefixes="COMMON,IMPL"
|
|
|
|
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -emit-llvm -pedantic -verify -O0 -o - | FileCheck %s --check-prefixes="COMMON,IMPL"
|
2018-12-13 18:15:27 +08:00
|
|
|
// expected-no-diagnostics
|
|
|
|
|
|
|
|
// Test that the 'this' pointer is in the __generic address space.
|
|
|
|
|
2019-01-30 19:18:08 +08:00
|
|
|
#ifdef USE_DEFLT
|
|
|
|
#define DEFAULT =default
|
|
|
|
#else
|
|
|
|
#define DEFAULT
|
|
|
|
#endif
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
class C {
|
|
|
|
public:
|
|
|
|
int v;
|
2019-01-30 19:18:08 +08:00
|
|
|
#ifdef DECL
|
|
|
|
C() DEFAULT;
|
|
|
|
C(C &&c) DEFAULT;
|
|
|
|
C(const C &c) DEFAULT;
|
|
|
|
C &operator=(const C &c) DEFAULT;
|
|
|
|
C &operator=(C &&c) & DEFAULT;
|
|
|
|
#endif
|
2019-01-14 19:44:22 +08:00
|
|
|
C operator+(const C& c) {
|
|
|
|
v += c.v;
|
|
|
|
return *this;
|
|
|
|
}
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
int get() { return v; }
|
|
|
|
|
|
|
|
int outside();
|
|
|
|
};
|
|
|
|
|
2019-01-30 19:18:08 +08:00
|
|
|
#if defined(DECL) && !defined(USE_DEFLT)
|
|
|
|
C::C() { v = 2; };
|
|
|
|
|
|
|
|
C::C(C &&c) { v = c.v; }
|
|
|
|
|
|
|
|
C::C(const C &c) { v = c.v; }
|
|
|
|
|
|
|
|
C &C::operator=(const C &c) {
|
|
|
|
v = c.v;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
C &C::operator=(C &&c) & {
|
|
|
|
v = c.v;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-13 18:15:27 +08:00
|
|
|
int C::outside() {
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern C&& foo();
|
|
|
|
|
|
|
|
__global C c;
|
|
|
|
|
|
|
|
__kernel void test__global() {
|
|
|
|
int i = c.get();
|
2019-05-03 00:10:50 +08:00
|
|
|
int i2 = (&c)->get();
|
|
|
|
int i3 = c.outside();
|
2018-12-13 18:15:27 +08:00
|
|
|
C c1(c);
|
|
|
|
C c2;
|
|
|
|
c2 = c1;
|
2019-01-14 19:44:22 +08:00
|
|
|
C c3 = c1 + c2;
|
|
|
|
C c4(foo());
|
|
|
|
C c5 = foo();
|
2018-12-13 18:15:27 +08:00
|
|
|
}
|
|
|
|
|
2019-01-30 19:18:08 +08:00
|
|
|
// Test that the address space is __generic for all members
|
|
|
|
// EXPL: @_ZNU3AS41CC2Ev(%class.C addrspace(4)* %this)
|
|
|
|
// EXPL: @_ZNU3AS41CC1Ev(%class.C addrspace(4)* %this)
|
|
|
|
// EXPL: @_ZNU3AS41CC2EOU3AS4S_(%class.C addrspace(4)* %this
|
|
|
|
// EXPL: @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* %this
|
|
|
|
// EXPL: @_ZNU3AS41CC2ERU3AS4KS_(%class.C addrspace(4)* %this
|
|
|
|
// EXPL: @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* %this
|
|
|
|
// EXPL: @_ZNU3AS41CaSERU3AS4KS_(%class.C addrspace(4)* %this
|
|
|
|
// EXPL: @_ZNU3AS4R1CaSEOU3AS4S_(%class.C addrspace(4)* %this
|
|
|
|
// COMMON: @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* %this)
|
2018-12-13 18:15:27 +08:00
|
|
|
|
2019-01-30 19:18:08 +08:00
|
|
|
// EXPL-LABEL: @__cxx_global_var_init()
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
|
2018-12-13 18:15:27 +08:00
|
|
|
|
2019-05-07 22:22:34 +08:00
|
|
|
// COMMON-LABEL: @test__global()
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking a method.
|
2019-07-26 20:36:12 +08:00
|
|
|
// COMMON: call spir_func i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
|
2019-05-03 00:10:50 +08:00
|
|
|
// Test the address space of 'this' when invoking a method using a pointer to the object.
|
2019-07-26 20:36:12 +08:00
|
|
|
// COMMON: call spir_func i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking a method that is declared in the file contex.
|
2019-07-26 20:36:12 +08:00
|
|
|
// COMMON: call spir_func i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking copy-constructor.
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C1GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C1VOID:%[0-9]+]] = bitcast %class.C* %c1 to i8*
|
|
|
|
// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C1VOID]], i8 addrspace(4)* {{.*}}addrspacecast (i8 addrspace(1)* bitcast (%class.C addrspace(1)* @c to i8 addrspace(1)*) to i8 addrspace(4)*)
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking a constructor.
|
2019-07-11 01:10:05 +08:00
|
|
|
// EXPL: [[C2GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* [[C2GEN]])
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking assignment operator.
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C1GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
|
|
|
|
// COMMON: [[C2GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func dereferenceable(4) %class.C addrspace(4)* @_ZNU3AS41CaSERU3AS4KS_(%class.C addrspace(4)* [[C2GEN]], %class.C addrspace(4)* dereferenceable(4) [[C1GEN]])
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C2GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C2GEN]] to i8 addrspace(4)*
|
|
|
|
// IMPL: [[C1GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C1GEN]] to i8 addrspace(4)*
|
|
|
|
// IMPL: call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* {{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
|
2019-01-14 19:44:22 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking the operator+
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C1GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
|
|
|
|
// COMMON: [[C2GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// COMMON: call spir_func void @_ZNU3AS41CplERU3AS4KS_(%class.C* sret %c3, %class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[C2GEN]])
|
2019-01-14 19:44:22 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking the move constructor
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C4GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c4 to %class.C addrspace(4)*
|
2019-01-30 19:18:08 +08:00
|
|
|
// COMMON: [[CALL:%call[0-9]+]] = call spir_func dereferenceable(4) %class.C addrspace(4)* @_Z3foov()
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* [[C4GEN]], %class.C addrspace(4)* dereferenceable(4) [[CALL]])
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C4VOID:%[0-9]+]] = bitcast %class.C* %c4 to i8*
|
|
|
|
// IMPL: [[CALLVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[CALL]] to i8 addrspace(4)*
|
|
|
|
// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C4VOID]], i8 addrspace(4)* {{.*}}[[CALLVOID]]
|
2019-01-14 19:44:22 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking the move assignment
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C5GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c5 to %class.C addrspace(4)*
|
2019-01-30 19:18:08 +08:00
|
|
|
// COMMON: [[CALL:%call[0-9]+]] = call spir_func dereferenceable(4) %class.C addrspace(4)* @_Z3foov()
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* [[C5GEN]], %class.C addrspace(4)* dereferenceable(4) [[CALL]])
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C5VOID:%[0-9]+]] = bitcast %class.C* %c5 to i8*
|
|
|
|
// IMPL: [[CALLVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[CALL]] to i8 addrspace(4)*
|
|
|
|
// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C5VOID]], i8 addrspace(4)* {{.*}}[[CALLVOID]]
|
|
|
|
|
|
|
|
// Tests address space of inline members
|
|
|
|
//COMMON: @_ZNU3AS41C3getEv(%class.C addrspace(4)* %this)
|
|
|
|
//COMMON: @_ZNU3AS41CplERU3AS4KS_(%class.C* noalias sret %agg.result, %class.C addrspace(4)* %this
|
2018-12-13 18:15:27 +08:00
|
|
|
#define TEST(AS) \
|
|
|
|
__kernel void test##AS() { \
|
|
|
|
AS C c; \
|
|
|
|
int i = c.get(); \
|
|
|
|
C c1(c); \
|
|
|
|
C c2; \
|
|
|
|
c2 = c1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(__local)
|
|
|
|
|
2019-05-07 22:22:34 +08:00
|
|
|
// COMMON-LABEL: @test__local
|
2018-12-13 18:15:27 +08:00
|
|
|
|
2019-04-04 19:08:51 +08:00
|
|
|
// Test that we don't initialize an object in local address space.
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL-NOT: call spir_func void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localE1c to %class.C addrspace(4)*))
|
2018-12-13 18:15:27 +08:00
|
|
|
|
2019-01-14 19:44:22 +08:00
|
|
|
// Test the address space of 'this' when invoking a method.
|
2019-07-26 20:36:12 +08:00
|
|
|
// COMMON: call spir_func i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localE1c to %class.C addrspace(4)*))
|
2018-12-13 18:15:27 +08:00
|
|
|
|
2019-01-14 19:44:22 +08:00
|
|
|
// Test the address space of 'this' when invoking copy-constructor.
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C1GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) addrspacecast (%class.C addrspace(3)* @_ZZ11test__localE1c to %class.C addrspace(4)*))
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C1VOID:%[0-9]+]] = bitcast %class.C* %c1 to i8*
|
2019-05-07 22:22:34 +08:00
|
|
|
// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C1VOID]], i8 addrspace(4)* {{.*}}addrspacecast (i8 addrspace(3)* bitcast (%class.C addrspace(3)* @_ZZ11test__localE1c to i8 addrspace(3)*) to i8 addrspace(4)*), i32 4, i1 false)
|
2019-01-14 19:44:22 +08:00
|
|
|
|
2018-12-13 18:15:27 +08:00
|
|
|
// Test the address space of 'this' when invoking a constructor.
|
2019-07-11 01:10:05 +08:00
|
|
|
// EXPL: [[C2GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* [[C2GEN]])
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking assignment operator.
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C1GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
|
|
|
|
// COMMON: [[C2GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func dereferenceable(4) %class.C addrspace(4)* @_ZNU3AS41CaSERU3AS4KS_(%class.C addrspace(4)* [[C2GEN]], %class.C addrspace(4)* dereferenceable(4) [[C1GEN]])
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C2GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C2GEN]] to i8 addrspace(4)*
|
|
|
|
// IMPL: [[C1GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C1GEN]] to i8 addrspace(4)*
|
|
|
|
// IMPL: call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* {{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
TEST(__private)
|
|
|
|
|
2019-11-04 22:51:24 +08:00
|
|
|
// COMMON-LABEL: @test__private
|
2018-12-13 18:15:27 +08:00
|
|
|
|
2019-01-14 19:44:22 +08:00
|
|
|
// Test the address space of 'this' when invoking a constructor for an object in non-default address space
|
2019-07-11 01:10:05 +08:00
|
|
|
// EXPL: [[CGEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* [[CGEN]])
|
2019-01-14 19:44:22 +08:00
|
|
|
|
2018-12-13 18:15:27 +08:00
|
|
|
// Test the address space of 'this' when invoking a method.
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[CGEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// COMMON: call spir_func i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* [[CGEN]])
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking a copy-constructor.
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C1GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
|
|
|
|
// COMMON: [[CGEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[CGEN]])
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C1VOID:%[0-9]+]] = bitcast %class.C* %c1 to i8*
|
|
|
|
// IMPL: [[CGENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[CGEN]] to i8 addrspace(4)*
|
|
|
|
// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C1VOID]], i8 addrspace(4)* {{.*}}[[CGENVOID]]
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking a constructor.
|
2019-07-11 01:10:05 +08:00
|
|
|
// EXPL: [[C2GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* [[C2GEN]])
|
2018-12-13 18:15:27 +08:00
|
|
|
|
|
|
|
// Test the address space of 'this' when invoking a copy-assignment.
|
2019-07-11 01:10:05 +08:00
|
|
|
// COMMON: [[C1GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
|
|
|
|
// COMMON: [[C2GEN:%[.a-z0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
|
2019-07-26 20:36:12 +08:00
|
|
|
// EXPL: call spir_func dereferenceable(4) %class.C addrspace(4)* @_ZNU3AS41CaSERU3AS4KS_(%class.C addrspace(4)* [[C2GEN]], %class.C addrspace(4)* dereferenceable(4) [[C1GEN]])
|
2019-01-30 19:18:08 +08:00
|
|
|
// IMPL: [[C2GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C2GEN]] to i8 addrspace(4)*
|
|
|
|
// IMPL: [[C1GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C1GEN]] to i8 addrspace(4)*
|
|
|
|
// IMPL: call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* {{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
|
2019-11-04 21:12:17 +08:00
|
|
|
|
|
|
|
// Test that calling a const method from a non-const method does not crash Clang.
|
|
|
|
class ConstAndNonConstMethod {
|
|
|
|
public:
|
|
|
|
void DoConst() const {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoNonConst() {
|
|
|
|
DoConst();
|
|
|
|
}
|
|
|
|
};
|