File: reinterpret-cast.clcpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (37 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// 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}}
}