| 1 |
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -cl-std=CL2.0 |
| 2 |
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -cl-std=CL2.0 -DGENERIC |
| 3 |
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -cl-std=CL2.0 -DCONSTANT |
| 4 |
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -cl-std=CL2.0 -DLOCAL |
| 5 |
|
| 6 |
/* USM (unified shared memory) extension for OpenCLC 2.0 adds two new address |
| 7 |
* spaces: global_device and global_host that are a subset of __global address |
| 8 |
* space. As ISO/IEC TR 18037 5.1.3 declares - it's possible to implicitly |
| 9 |
* convert a subset address space to a superset address space, while conversion |
| 10 |
* in a reversed direction could be achieved only with an explicit cast */ |
| 11 |
|
| 12 |
#ifdef GENERIC |
| 13 |
#define AS_COMP __generic |
| 14 |
#else |
| 15 |
#define AS_COMP __global |
| 16 |
#endif // GENERIC |
| 17 |
|
| 18 |
#ifdef CONSTANT |
| 19 |
#define AS_INCOMP __constant |
| 20 |
#elif LOCAL |
| 21 |
#define AS_INCOMP __local |
| 22 |
#else // PRIVATE |
| 23 |
#define AS_INCOMP __private |
| 24 |
#endif // CONSTANT |
| 25 |
|
| 26 |
void test(AS_COMP int *arg_comp, |
| 27 |
__attribute__((opencl_global_device)) int *arg_device, |
| 28 |
__attribute__((opencl_global_host)) int *arg_host) { |
| 29 |
AS_COMP int *var_glob1 = arg_device; |
| 30 |
AS_COMP int *var_glob2 = arg_host; |
| 31 |
AS_COMP int *var_glob3 = (AS_COMP int *)arg_device; |
| 32 |
AS_COMP int *var_glob4 = (AS_COMP int *)arg_host; |
| 33 |
arg_device = (__attribute__((opencl_global_device)) int *)arg_comp; |
| 34 |
arg_host = (__attribute__((opencl_global_host)) int *)arg_comp; |
| 35 |
#ifdef GENERIC |
| 36 |
// expected-error@+6{{assigning '__generic int *__private' to '__global_device int *__private' changes address space of pointer}} |
| 37 |
// expected-error@+6{{assigning '__generic int *__private' to '__global_host int *__private' changes address space of pointer}} |
| 38 |
#else |
| 39 |
// expected-error@+3{{assigning '__global int *__private' to '__global_device int *__private' changes address space of pointer}} |
| 40 |
// expected-error@+3{{assigning '__global int *__private' to '__global_host int *__private' changes address space of pointer}} |
| 41 |
#endif // GENERIC |
| 42 |
arg_device = arg_comp; |
| 43 |
arg_host = arg_comp; |
| 44 |
|
| 45 |
#ifdef CONSTANT |
| 46 |
// expected-error@+15{{initializing '__constant int *__private' with an expression of type '__global_device int *__private' changes address space of pointer}} |
| 47 |
// expected-error@+15{{initializing '__constant int *__private' with an expression of type '__global_host int *__private' changes address space of pointer}} |
| 48 |
// expected-error@+15{{initializing '__constant int *__private' with an expression of type '__global_device int *' changes address space of pointer}} |
| 49 |
// expected-error@+16{{initializing '__constant int *__private' with an expression of type '__global_host int *' changes address space of pointer}} |
| 50 |
#elif LOCAL |
| 51 |
// expected-error@+10{{initializing '__local int *__private' with an expression of type '__global_device int *__private' changes address space of pointer}} |
| 52 |
// expected-error@+10{{initializing '__local int *__private' with an expression of type '__global_host int *__private' changes address space of pointer}} |
| 53 |
// expected-error@+10{{initializing '__local int *__private' with an expression of type '__global_device int *' changes address space of pointer}} |
| 54 |
// expected-error@+11{{initializing '__local int *__private' with an expression of type '__global_host int *' changes address space of pointer}} |
| 55 |
#else // PRIVATE |
| 56 |
// expected-error@+5{{initializing '__private int *__private' with an expression of type '__global_device int *__private' changes address space of pointer}} |
| 57 |
// expected-error@+5{{initializing '__private int *__private' with an expression of type '__global_host int *__private' changes address space of pointer}} |
| 58 |
// expected-error@+5{{initializing '__private int *__private' with an expression of type '__global_device int *' changes address space of pointer}} |
| 59 |
// expected-error@+6{{initializing '__private int *__private' with an expression of type '__global_host int *' changes address space of pointer}} |
| 60 |
#endif // CONSTANT |
| 61 |
AS_INCOMP int *var_incomp1 = arg_device; |
| 62 |
AS_INCOMP int *var_incomp2 = arg_host; |
| 63 |
AS_INCOMP int *var_incomp3 = |
| 64 |
(__attribute__((opencl_global_device)) int *)arg_device; |
| 65 |
AS_INCOMP int *var_incomp4 = |
| 66 |
(__attribute__((opencl_global_host)) int *)arg_host; |
| 67 |
} |