xref: /llvm-project/clang/test/SemaOpenCLCXX/addrspace_cast.clcpp (revision 85255a04e5729c03214c51177aa885c055f3e242)
1// RUN: %clang_cc1 %s -triple spir-unknown-unknown -pedantic -verify -fsyntax-only
2
3void foo(global int *gl, const global int *gl_const, global int &gl_ref) {
4  //FIXME: Diagnostics can be improved to be more specific in some cases.
5  float *gen_fl = addrspace_cast<float *>(gl); //expected-error{{addrspace_cast from '__global int *__private' to '__generic float *' is not allowed}}
6
7  int i = addrspace_cast<int>(gl); //expected-error{{addrspace_cast from '__global int *__private' to 'int' is not allowed}}
8
9  int *gen = addrspace_cast<int *>(*gl); //expected-error{{addrspace_cast from '__global int' to '__generic int *' is not allowed}}
10
11  local int *loc = addrspace_cast<local int *>(gl); //expected-error{{addrspace_cast from '__global int *__private' to '__local int *' converts between mismatching address spaces}}
12
13  int *gen2 = addrspace_cast<int *>(gl_const); //expected-error{{addrspace_cast from 'const __global int *__private' to '__generic int *' is not allowed}}
14
15  //FIXME: Do we expect this behavior? This will get cast successfully as reinterpret_cast.
16  int &gen_ref = addrspace_cast<int &>(gl_ref); //expected-error{{addrspace_cast from '__global int' to '__generic int &' is not allowed}}
17
18  __private int *priv = addrspace_cast<__private int *>(&i);
19}
20
21template <class T>
22void test_temp(__global int *par) {
23  T *var1 = addrspace_cast<T *>(par); //expected-error{{addrspace_cast from '__global int *__private' to '__private int *' converts between mismatching address spaces}}
24  __private T *var2 = addrspace_cast<__private T *>(par); //expected-error{{addrspace_cast from '__global int *__private' to '__private int *' converts between mismatching address spaces}}
25  T var3 = addrspace_cast<T>(par); //expected-error{{addrspace_cast from '__global int *__private' to 'int' is not allowed}}
26}
27
28void bar() {
29  __global int* var;
30  test_temp<__private int>(var); //expected-note{{in instantiation of function template specialization 'test_temp<__private int>' requested here}}
31}
32// We don't give any errors on non-instantiated template as types are not concrete yet.
33template <class T>
34void test_temp1(__global int *par) {
35  T *var1 = addrspace_cast<T *>(par);
36  __private T *var2 = addrspace_cast<__private T *>(par);
37  T var3 = addrspace_cast<T>(par);
38}
39
40