llvm-project/clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.6 KiB
Plaintext
Raw Normal View History

// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only
typedef int int2 __attribute__((ext_vector_type(2)));
typedef int int3 __attribute__((ext_vector_type(3)));
typedef int int4 __attribute__((ext_vector_type(4)));
struct X {};
__global int g = 0;
__global int *__global g_ptr = &g;
kernel void foo() {
// Testing conversions between vectors and vectors/scalars
long l1;
auto l_to_i2 = reinterpret_cast<int2>(l1);
int2 i2;
auto i2_to_l = reinterpret_cast<long>(i2);
auto i2_to_i = reinterpret_cast<int>(i2); // expected-error{{reinterpret_cast from vector 'int2' (vector of 2 'int' values) to scalar 'int' of different size}}
auto i2_to_i2 = reinterpret_cast<int2>(i2);
// Testing reinterpret_cast with address spaces.
__private short s;
auto s2 = reinterpret_cast<__private short>(s);
auto s3 = reinterpret_cast<decltype(s)>(s);
auto s4 = reinterpret_cast<__global short>(s);
__private X x;
auto x2 = reinterpret_cast<__private X>(x); // expected-error{{reinterpret_cast from '__private X' to '__private X' is not allowed}}
auto ptr = reinterpret_cast<__global int* __private>(g_ptr);
(void)reinterpret_cast<__private int* __private>(g_ptr); // expected-error{{reinterpret_cast from '__global int *' to '__private int *' is not allowed}}
// Only integral types (and pointer/references) can be reinterpret casted to themselves.
// Currently this does not include any opencl types.
reserve_id_t r_id1;
auto r_id2 = reinterpret_cast<reserve_id_t>(r_id1); // expected-error{{reinterpret_cast from 'reserve_id_t' to 'reserve_id_t' is not allowed}}
}