[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang / test / SemaOpenCL / access-qualifier.cl
blobd1c9b5e35af6cd3aeb7719bf7d1412be6e87661f
1 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s -cl-ext=-cl_khr_3d_image_writes
2 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
3 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s
4 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s -cl-ext=-__opencl_c_read_write_images
5 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=clc++2021 %s
6 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=clc++2021 %s -cl-ext=-__opencl_c_read_write_images
8 typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
10 typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
11 typedef read_only image1d_t img1d_ro;
13 #if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images))
14 typedef read_write image1d_t img1d_rw;
15 #endif
17 typedef int Int;
18 typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}}
20 void myWrite(write_only image1d_t);
21 #if !defined(__OPENCL_CPP_VERSION__)
22 // expected-note@-2 {{passing argument to parameter here}}
23 // expected-note@-3 {{passing argument to parameter here}}
24 #else
25 // expected-note@-5 {{candidate function not viable: no known conversion from '__private img1d_ro' (aka '__private __read_only image1d_t') to '__private __write_only image1d_t' for 1st argument}}
26 // expected-note@-6 {{candidate function not viable: no known conversion from '__private img1d_ro_default' (aka '__private __read_only image1d_t') to '__private __write_only image1d_t' for 1st argument}}
27 #endif
29 void myRead(read_only image1d_t);
30 #if !defined(__OPENCL_CPP_VERSION__)
31 // expected-note@-2 {{passing argument to parameter here}}
32 #else
33 // expected-note@-4 {{candidate function not viable: no known conversion from '__private img1d_wo' (aka '__private __write_only image1d_t') to '__private __read_only image1d_t' for 1st argument}}
34 #endif
36 #if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images))
37 void myReadWrite(read_write image1d_t);
38 #else
39 void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' cannot be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in version 3.0 and without __opencl_c_read_write_images feature}}
40 #endif
43 kernel void k1(img1d_wo img) {
44 myRead(img);
45 #if !defined(__OPENCL_CPP_VERSION__)
46 // expected-error@-2 {{passing '__private img1d_wo' (aka '__private __write_only image1d_t') to parameter of incompatible type '__read_only image1d_t'}}
47 #else
48 // expected-error@-4 {{no matching function for call to 'myRead'}}
49 #endif
52 kernel void k2(img1d_ro img) {
53 myWrite(img);
54 #if !defined(__OPENCL_CPP_VERSION__)
55 // expected-error@-2 {{passing '__private img1d_ro' (aka '__private __read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
56 #else
57 // expected-error@-4 {{no matching function for call to 'myWrite'}}
58 #endif
61 kernel void k3(img1d_wo img) {
62 myWrite(img);
65 #if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images))
66 kernel void k4(img1d_rw img) {
67 myReadWrite(img);
69 #endif
71 kernel void k5(img1d_ro_default img) {
72 myWrite(img);
73 #if !defined(__OPENCL_CPP_VERSION__)
74 // expected-error@-2 {{passing '__private img1d_ro_default' (aka '__private __read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
75 #else
76 // expected-error@-4 {{no matching function for call to 'myWrite'}}
77 #endif
80 kernel void k6(img1d_ro img) {
81 myRead(img);
84 kernel void k7(read_only img1d_wo img){} // expected-error {{multiple access qualifiers}}
86 kernel void k8(write_only img1d_ro_default img){} // expected-error {{multiple access qualifiers}}
88 kernel void k9(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
90 kernel void k10(read_only Int img){} // expected-error {{access qualifier can only be used for pipe and image type}}
92 kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
94 kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
96 #if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images))
97 kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' cannot be used for 'read_only pipe int'}}
98 #else
99 kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' cannot be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in version 3.0 and without __opencl_c_read_write_images feature}}
100 #endif
102 #if defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 200
103 kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes support}}
104 #endif
106 #if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images))
107 kernel void read_write_twice_typedef(read_write img1d_rw i){} // expected-warning {{duplicate 'read_write' declaration specifier}}
108 // expected-note@-94 {{previously declared 'read_write' here}}
109 #endif
111 #if __OPENCL_C_VERSION__ >= 200
112 void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
113 kernel void k14(read_only pipe int p) {
114 myPipeWrite(p); // expected-error {{passing '__private read_only pipe int' to parameter of incompatible type 'write_only pipe int'}}
117 kernel void pipe_ro_twice(read_only read_only pipe int i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
118 // Conflicting access qualifiers
119 kernel void pipe_ro_twice_tw(read_write read_only read_only pipe int i){} // expected-error{{access qualifier 'read_write' cannot be used for 'read_only pipe int'}}
120 kernel void pipe_ro_wo(read_only write_only pipe int i){} // expected-error{{multiple access qualifiers}}
122 typedef read_only pipe int ROPipeInt;
123 kernel void pipe_ro_twice_typedef(read_only ROPipeInt i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
124 // expected-note@-2 {{previously declared 'read_only' here}}
126 kernel void pass_ro_typedef_to_wo(ROPipeInt p) {
127 myPipeWrite(p); // expected-error {{passing '__private ROPipeInt' (aka '__private read_only pipe int') to parameter of incompatible type 'write_only pipe int'}}
128 // expected-note@-16 {{passing argument to parameter here}}
130 #endif
132 kernel void read_only_twice_typedef(__read_only img1d_ro i){} // expected-warning {{duplicate '__read_only' declaration specifier}}
133 // expected-note@-122 {{previously declared 'read_only' here}}
135 kernel void read_only_twice_default(read_only img1d_ro_default img){} // expected-warning {{duplicate 'read_only' declaration specifier}}
136 // expected-note@-128 {{previously declared 'read_only' here}}
138 kernel void image_wo_twice(write_only __write_only image1d_t i){} // expected-warning {{duplicate '__write_only' declaration specifier}}
139 kernel void image_wo_twice_typedef(write_only img1d_wo i){} // expected-warning {{duplicate 'write_only' declaration specifier}}
140 // expected-note@-130 {{previously declared 'write_only' here}}