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