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 7 8typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}} 9 10typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}} 11typedef read_only image1d_t img1d_ro; 12 13#if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images)) 14typedef read_write image1d_t img1d_rw; 15#endif 16 17typedef int Int; 18typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}} 19 20void 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 28 29void 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 35 36#if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images)) 37void myReadWrite(read_write image1d_t); 38#else 39void 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 41 42 43kernel 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 50} 51 52kernel 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 59} 60 61kernel void k3(img1d_wo img) { 62 myWrite(img); 63} 64 65#if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images)) 66kernel void k4(img1d_rw img) { 67 myReadWrite(img); 68} 69#endif 70 71kernel 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 78} 79 80kernel void k6(img1d_ro img) { 81 myRead(img); 82} 83 84kernel void k7(read_only img1d_wo img){} // expected-error {{multiple access qualifiers}} 85 86kernel void k8(write_only img1d_ro_default img){} // expected-error {{multiple access qualifiers}} 87 88kernel void k9(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}} 89 90kernel void k10(read_only Int img){} // expected-error {{access qualifier can only be used for pipe and image type}} 91 92kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}} 93 94kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}} 95 96#if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images)) 97kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' cannot be used for 'read_only pipe int'}} 98#else 99kernel 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 101 102#if defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 200 103kernel 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 105 106#if (__OPENCL_C_VERSION__ == 200) || ((__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) && defined(__opencl_c_read_write_images)) 107kernel 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 110 111#if __OPENCL_C_VERSION__ >= 200 112void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}} 113kernel 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'}} 115} 116 117kernel void pipe_ro_twice(read_only read_only pipe int i){} // expected-warning{{duplicate 'read_only' declaration specifier}} 118// Conflicting access qualifiers 119kernel 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'}} 120kernel void pipe_ro_wo(read_only write_only pipe int i){} // expected-error{{multiple access qualifiers}} 121 122typedef read_only pipe int ROPipeInt; 123kernel 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}} 125 126kernel 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}} 129} 130#endif 131 132kernel 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}} 134 135kernel 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}} 137 138kernel void image_wo_twice(write_only __write_only image1d_t i){} // expected-warning {{duplicate '__write_only' declaration specifier}} 139kernel 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}} 141