[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Parser / opencl-atomics-cl20.cl
blob2648142f28e7cd4fde0468f710a0ba3aedc6042c
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 -cl-ext=-cl_khr_int64_base_atomics
3 // RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0
4 // RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only -cl-std=CLC++
5 // RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -cl-ext=-cl_khr_int64_base_atomics
7 #if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0
8 #define LANG_VER_OK
9 #endif
11 void atomic_types_test(void) {
12 // OpenCL v2.0 s6.13.11.6 defines supported atomic types.
14 // Non-optional types
15 atomic_int i;
16 atomic_uint ui;
17 atomic_float f;
18 atomic_flag fl;
19 #if !defined(LANG_VER_OK)
20 // expected-error@-5 {{use of undeclared identifier 'atomic_int'}}
21 // expected-error@-5 {{use of undeclared identifier 'atomic_uint'}}
22 // expected-error@-5 {{use of undeclared identifier 'atomic_float'}}
23 // expected-error@-5 {{use of undeclared identifier 'atomic_flag'}}
24 #endif
26 // Optional types
27 atomic_long l;
28 atomic_ulong ul;
29 atomic_double d;
30 atomic_size_t s;
31 atomic_intptr_t ip;
32 atomic_uintptr_t uip;
33 atomic_ptrdiff_t pd;
34 // Optional type identifiers are not added in earlier version or if at least
35 // one of the extensions is not supported. Here we check with
36 // `cl_khr_int64_base_atomics` only.
37 #if !defined(LANG_VER_OK) || !defined(cl_khr_int64_base_atomics)
38 // expected-error@-11 {{use of undeclared identifier 'atomic_long'}}
39 // expected-error@-11 {{use of undeclared identifier 'atomic_ulong'}}
40 // expected-error@-11 {{use of undeclared identifier 'atomic_double'}}
41 #if defined(LANG_VER_OK)
42 // expected-error@-15 {{expected ';' after expression}}
43 // expected-error@-16 {{use of undeclared identifier 'l'}}
44 // expected-error@-16 {{expected ';' after expression}}
45 // expected-error@-17 {{use of undeclared identifier 'ul'}}
46 #endif
47 #if !defined(LANG_VER_OK) || defined(__SPIR64__)
48 // expected-error@-18 {{use of undeclared identifier 'atomic_size_t'}}
49 // expected-error@-16 {{use of undeclared identifier 'atomic_ptrdiff_t'}}
50 #if !defined(LANG_VER_OK)
51 // expected-error@-20 {{use of undeclared identifier 'atomic_intptr_t'}}
52 // expected-error@-20 {{use of undeclared identifier 'atomic_uintptr_t'}}
53 #else
54 // expected-error@-24 {{expected ';' after expression}}
55 // expected-error@-25 {{use of undeclared identifier 's'}}
56 // expected-error@-25 {{unknown type name 'atomic_intptr_t'; did you mean 'atomic_int'?}}
57 // expected-note@* {{'atomic_int' declared here}}
58 // expected-error@-26 {{unknown type name 'atomic_uintptr_t'; did you mean 'atomic_uint'?}}
59 // expected-note@* {{'atomic_uint' declared here}}
60 #endif
61 #endif
62 #endif
64 // OpenCL v2.0 s6.13.11.8, _Atomic type specifier and _Atomic type qualifier
65 // are not supported by OpenCL.
66 _Atomic int i;
67 #ifdef __OPENCL_C_VERSION__
68 // expected-error@-2 {{use of undeclared identifier '_Atomic'}}
69 #else
70 // expected-error@-4 {{unknown type name '_Atomic'}}
71 #endif
74 #if defined(LANG_VER_OK)
75 int atomic_uint; //expected-error{{redefinition of 'atomic_uint' as different kind of symbol}}
76 void foo(atomic_int * ptr) {}
77 void atomic_ops_test() {
78 atomic_int i;
79 foo(&i);
80 // OpenCL v2.0 s6.13.11.8, arithemtic operations are not permitted on atomic types.
81 i++; // expected-error {{invalid argument type '__private atomic_int' (aka '__private _Atomic(int)') to unary expression}}
82 i = 1; // expected-error {{atomic variable can be assigned to a variable only in global address space}}
83 i += 1; // expected-error {{invalid operands to binary expression ('__private atomic_int' (aka '__private _Atomic(int)') and 'int')}}
84 i = i + i; // expected-error {{invalid operands to binary expression ('__private atomic_int' (aka '__private _Atomic(int)') and '__private atomic_int')}}
86 #else
87 __constant int atomic_uint = 1;
88 #endif