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
6typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
7
8typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
9typedef read_only image1d_t img1d_ro;
10
11#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
12typedef read_write image1d_t img1d_rw;
13#endif
14
15typedef int Int;
16typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}}
17
18
19void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
20void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
21
22#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
23void myReadWrite(read_write image1d_t);
24#else
25void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not 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}}
26#endif
27
28
29kernel void k1(img1d_wo img) {
30  myRead(img); // expected-error {{passing '__private img1d_wo' (aka '__private __write_only image1d_t') to parameter of incompatible type '__read_only image1d_t'}}
31}
32
33kernel void k2(img1d_ro img) {
34  myWrite(img); // expected-error {{passing '__private img1d_ro' (aka '__private __read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
35}
36
37kernel void k3(img1d_wo img) {
38  myWrite(img);
39}
40
41#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
42kernel void k4(img1d_rw img) {
43  myReadWrite(img);
44}
45#endif
46
47kernel void k5(img1d_ro_default img) {
48  myWrite(img); // expected-error {{passing '__private img1d_ro_default' (aka '__private __read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
49}
50
51kernel void k6(img1d_ro img) {
52  myRead(img);
53}
54
55kernel void k7(read_only img1d_wo img){} // expected-error {{multiple access qualifiers}}
56
57kernel void k8(write_only img1d_ro_default img){} // expected-error {{multiple access qualifiers}}
58
59kernel void k9(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
60
61kernel void k10(read_only Int img){} // expected-error {{access qualifier can only be used for pipe and image type}}
62
63kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
64
65kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
66
67#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
68kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
69#else
70kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not 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}}
71#endif
72
73#if __OPENCL_C_VERSION__ < 200
74kernel 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}}
75#endif
76
77#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
78kernel void read_write_twice_typedef(read_write img1d_rw i){} // expected-warning {{duplicate 'read_write' declaration specifier}}
79// expected-note@-67 {{previously declared 'read_write' here}}
80#endif
81
82#if OPENCL_C_VERSION__ >= 200
83void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
84kernel void k14(read_only pipe int p) {
85  myPipeWrite(p); // expected-error {{passing '__private read_only pipe int' to parameter of incompatible type 'write_only pipe int'}}
86}
87
88kernel void pipe_ro_twice(read_only read_only pipe int i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
89// Conflicting access qualifiers
90kernel void pipe_ro_twice_tw(read_write read_only read_only pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
91kernel void pipe_ro_wo(read_only write_only pipe int i){} // expected-error{{multiple access qualifiers}}
92
93typedef read_only pipe int ROPipeInt;
94kernel void pipe_ro_twice_typedef(read_only ROPipeInt i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
95// expected-note@-2 {{previously declared 'read_only' here}}
96
97kernel void pass_ro_typedef_to_wo(ROPipeInt p) {
98  myPipeWrite(p); // expected-error {{passing '__private ROPipeInt' (aka '__private read_only pipe int') to parameter of incompatible type 'write_only pipe int'}}
99  // expected-note@-16 {{passing argument to parameter here}}
100}
101#endif
102
103kernel void read_only_twice_typedef(__read_only img1d_ro i){} // expected-warning {{duplicate '__read_only' declaration specifier}}
104// expected-note@-95 {{previously declared 'read_only' here}}
105
106kernel void read_only_twice_default(read_only img1d_ro_default img){} // expected-warning {{duplicate 'read_only' declaration specifier}}
107// expected-note@-101 {{previously declared 'read_only' here}}
108
109kernel void image_wo_twice(write_only __write_only image1d_t i){} // expected-warning {{duplicate '__write_only' declaration specifier}}
110kernel void image_wo_twice_typedef(write_only img1d_wo i){} // expected-warning {{duplicate 'write_only' declaration specifier}}
111// expected-note@-103 {{previously declared 'write_only' here}}
112
113