| 1 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only |
| 2 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -DCL20 |
| 3 | // RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -DCL20 |
| 4 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -DCL20 -DEXT -Wpedantic-core-features |
| 5 | |
| 6 | #ifdef EXT |
| 7 | #pragma OPENCL EXTENSION cl_khr_int64_base_atomics:enable |
| 8 | #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics:enable |
| 9 | #pragma OPENCL EXTENSION cl_khr_fp64:enable |
| 10 | #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2 |
| 11 | // expected-warning@-2{{OpenCL extension 'cl_khr_fp64' is core feature or supported optional core feature - ignoring}} |
| 12 | #endif |
| 13 | #endif |
| 14 | |
| 15 | void atomic_types_test() { |
| 16 | // OpenCL v2.0 s6.13.11.6 defines supported atomic types. |
| 17 | atomic_int i; |
| 18 | atomic_uint ui; |
| 19 | atomic_long l; |
| 20 | atomic_ulong ul; |
| 21 | atomic_float f; |
| 22 | atomic_double d; |
| 23 | atomic_flag fl; |
| 24 | atomic_intptr_t ip; |
| 25 | atomic_uintptr_t uip; |
| 26 | atomic_size_t s; |
| 27 | atomic_ptrdiff_t pd; |
| 28 | // OpenCL v2.0 s6.13.11.8, _Atomic type specifier and _Atomic type qualifier |
| 29 | // are not supported by OpenCL. |
| 30 | _Atomic int i; // expected-error {{use of undeclared identifier '_Atomic'}} |
| 31 | } |
| 32 | #ifndef CL20 |
| 33 | // expected-error@-16 {{use of undeclared identifier 'atomic_int'}} |
| 34 | // expected-error@-16 {{use of undeclared identifier 'atomic_uint'}} |
| 35 | // expected-error@-16 {{use of undeclared identifier 'atomic_long'}} |
| 36 | // expected-error@-16 {{use of undeclared identifier 'atomic_ulong'}} |
| 37 | // expected-error@-16 {{use of undeclared identifier 'atomic_float'}} |
| 38 | // expected-error@-16 {{use of undeclared identifier 'atomic_double'}} |
| 39 | // expected-error@-16 {{use of undeclared identifier 'atomic_flag'}} |
| 40 | // expected-error@-16 {{use of undeclared identifier 'atomic_intptr_t'}} |
| 41 | // expected-error@-16 {{use of undeclared identifier 'atomic_uintptr_t'}} |
| 42 | // expected-error@-16 {{use of undeclared identifier 'atomic_size_t'}} |
| 43 | // expected-error@-16 {{use of undeclared identifier 'atomic_ptrdiff_t'}} |
| 44 | #elif !EXT |
| 45 | // expected-error@-26 {{use of type 'atomic_long' (aka '_Atomic(long)') requires cl_khr_int64_base_atomics extension to be enabled}} |
| 46 | // expected-error@-27 {{use of type 'atomic_long' (aka '_Atomic(long)') requires cl_khr_int64_extended_atomics extension to be enabled}} |
| 47 | // expected-error@-27 {{use of type 'atomic_ulong' (aka '_Atomic(unsigned long)') requires cl_khr_int64_base_atomics extension to be enabled}} |
| 48 | // expected-error@-28 {{use of type 'atomic_ulong' (aka '_Atomic(unsigned long)') requires cl_khr_int64_extended_atomics extension to be enabled}} |
| 49 | // expected-error@-27 {{use of type 'atomic_double' (aka '_Atomic(double)') requires cl_khr_int64_base_atomics extension to be enabled}} |
| 50 | // expected-error@-28 {{use of type 'atomic_double' (aka '_Atomic(double)') requires cl_khr_int64_extended_atomics extension to be enabled}} |
| 51 | #if __LP64__ |
| 52 | // expected-error-re@-28 {{use of type 'atomic_intptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} |
| 53 | // expected-error-re@-29 {{use of type 'atomic_intptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} |
| 54 | // expected-error-re@-29 {{use of type 'atomic_uintptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} |
| 55 | // expected-error-re@-30 {{use of type 'atomic_uintptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} |
| 56 | // expected-error-re@-30 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} |
| 57 | // expected-error-re@-31 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} |
| 58 | // expected-error-re@-31 {{use of type 'atomic_ptrdiff_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} |
| 59 | // expected-error-re@-32 {{use of type 'atomic_ptrdiff_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} |
| 60 | #endif |
| 61 | #endif |
| 62 | |
| 63 | #ifdef CL20 |
| 64 | void foo(atomic_int * ptr) {} |
| 65 | void atomic_ops_test() { |
| 66 | atomic_int i; |
| 67 | foo(&i); |
| 68 | // OpenCL v2.0 s6.13.11.8, arithemtic operations are not permitted on atomic types. |
| 69 | i++; // expected-error {{invalid argument type 'atomic_int' (aka '_Atomic(int)') to unary expression}} |
| 70 | i = 1; // expected-error {{atomic variable can be assigned to a variable only in global address space}} |
| 71 | i += 1; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'int')}} |
| 72 | i = i + i; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'atomic_int')}} |
| 73 | } |
| 74 | #endif |
| 75 | |