File: opencl-atomics-cl20.cl

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (88 lines) | stat: -rw-r--r-- 3,914 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -cl-ext=-cl_khr_int64_base_atomics
// RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0
// RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only -cl-std=CLC++
// RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -cl-ext=-cl_khr_int64_base_atomics

#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0
#define LANG_VER_OK
#endif

void atomic_types_test(void) {
// OpenCL v2.0 s6.13.11.6 defines supported atomic types.

// Non-optional types
  atomic_int i;
  atomic_uint ui;
  atomic_float f;
  atomic_flag fl;
#if !defined(LANG_VER_OK)
// expected-error@-5 {{use of undeclared identifier 'atomic_int'}}
// expected-error@-5 {{use of undeclared identifier 'atomic_uint'}}
// expected-error@-5 {{use of undeclared identifier 'atomic_float'}}
// expected-error@-5 {{use of undeclared identifier 'atomic_flag'}}
#endif

// Optional types
  atomic_long l;
  atomic_ulong ul;
  atomic_double d;
  atomic_size_t s;
  atomic_intptr_t ip;
  atomic_uintptr_t uip;
  atomic_ptrdiff_t pd;
// Optional type identifiers are not added in earlier version or if at least
// one of the extensions is not supported. Here we check with
// `cl_khr_int64_base_atomics` only.
#if !defined(LANG_VER_OK) || !defined(cl_khr_int64_base_atomics)
// expected-error@-11 {{use of undeclared identifier 'atomic_long'}}
// expected-error@-11 {{use of undeclared identifier 'atomic_ulong'}}
// expected-error@-11 {{use of undeclared identifier 'atomic_double'}}
#if defined(LANG_VER_OK)
// expected-error@-15 {{expected ';' after expression}}
// expected-error@-16 {{use of undeclared identifier 'l'}}
// expected-error@-16 {{expected ';' after expression}}
// expected-error@-17 {{use of undeclared identifier 'ul'}}
#endif
#if !defined(LANG_VER_OK) || defined(__SPIR64__)
// expected-error@-18 {{use of undeclared identifier 'atomic_size_t'}}
// expected-error@-16 {{use of undeclared identifier 'atomic_ptrdiff_t'}}
#if !defined(LANG_VER_OK)
// expected-error@-20 {{use of undeclared identifier 'atomic_intptr_t'}}
// expected-error@-20 {{use of undeclared identifier 'atomic_uintptr_t'}}
#else
// expected-error@-24 {{expected ';' after expression}}
// expected-error@-25 {{use of undeclared identifier 's'}}
// expected-error@-25 {{unknown type name 'atomic_intptr_t'; did you mean 'atomic_int'?}}
// expected-note@* {{'atomic_int' declared here}}
// expected-error@-26 {{unknown type name 'atomic_uintptr_t'; did you mean 'atomic_uint'?}}
// expected-note@* {{'atomic_uint' declared here}}
#endif
#endif
#endif

// OpenCL v2.0 s6.13.11.8, _Atomic type specifier and _Atomic type qualifier
// are not supported by OpenCL.
  _Atomic int i;
#ifdef __OPENCL_C_VERSION__
// expected-error@-2 {{use of undeclared identifier '_Atomic'}}
#else
 // expected-error@-4 {{unknown type name '_Atomic'}}
#endif
}

#if defined(LANG_VER_OK)
int atomic_uint; //expected-error{{redefinition of 'atomic_uint' as different kind of symbol}}
void foo(atomic_int * ptr) {}
void atomic_ops_test() {
  atomic_int i;
  foo(&i);
// OpenCL v2.0 s6.13.11.8, arithemtic operations are not permitted on atomic types.
  i++; // expected-error {{invalid argument type '__private atomic_int' (aka '__private _Atomic(int)') to unary expression}}
  i = 1; // expected-error {{atomic variable can be assigned to a variable only in global address space}}
  i += 1; // expected-error {{invalid operands to binary expression ('__private atomic_int' (aka '__private _Atomic(int)') and 'int')}}
  i = i + i; // expected-error {{invalid operands to binary expression ('__private atomic_int' (aka '__private _Atomic(int)') and '__private atomic_int')}}
}
#else
__constant int atomic_uint = 1;
#endif