Clang Project

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