Debian Codegraph @

clang/test/Parser/opencl-atomics-cl20.cl

raw
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
6
7 #if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0
8 #define LANG_VER_OK
9 #endif
10
11 void atomic_types_test(void) {
12 // OpenCL v2.0 s6.13.11.6 defines supported atomic types.
13
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
25
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 #endif
43 #if !defined(LANG_VER_OK) || defined(__SPIR64__)
44 // expected-error@-14 {{use of undeclared identifier 'atomic_size_t'}}
45 // expected-error@-12 {{use of undeclared identifier 'atomic_ptrdiff_t'}}
46 #if !defined(LANG_VER_OK)
47 // expected-error@-16 {{use of undeclared identifier 'atomic_intptr_t'}}
48 // expected-error@-16 {{use of undeclared identifier 'atomic_uintptr_t'}}
49 #else
50 // expected-error@-19 {{unknown type name 'atomic_intptr_t'; did you mean 'atomic_int'?}}
51 // expected-note@* {{'atomic_int' declared here}}
52 // expected-error@-20 {{unknown type name 'atomic_uintptr_t'; did you mean 'atomic_uint'?}}
53 // expected-note@* {{'atomic_uint' declared here}}
54 #endif
55 #endif
56 #endif
57
58 // OpenCL v2.0 s6.13.11.8, _Atomic type specifier and _Atomic type qualifier
59 // are not supported by OpenCL.
60 _Atomic int i;
61 #ifdef __OPENCL_C_VERSION__
62 // expected-error@-2 {{use of undeclared identifier '_Atomic'}}
63 #else
64 // expected-error@-4 {{unknown type name '_Atomic'}}
65 #endif
66 }
67
68 #if defined(LANG_VER_OK)
69 int atomic_uint; //expected-error{{redefinition of 'atomic_uint' as different kind of symbol}}
70 void foo(atomic_int * ptr) {}
71 void atomic_ops_test() {
72 atomic_int i;
73 foo(&i);
74 // OpenCL v2.0 s6.13.11.8, arithemtic operations are not permitted on atomic types.
75 i++; // expected-error {{invalid argument type '__private atomic_int' (aka '__private _Atomic(int)') to unary expression}}
76 i = 1; // expected-error {{atomic variable can be assigned to a variable only in global address space}}
77 i += 1; // expected-error {{invalid operands to binary expression ('__private atomic_int' (aka '__private _Atomic(int)') and 'int')}}
78 i = i + i; // expected-error {{invalid operands to binary expression ('__private atomic_int' (aka '__private _Atomic(int)') and '__private atomic_int')}}
79 }
80 #else
81 __constant int atomic_uint = 1;
82 #endif