1 | // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= |
2 | // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile" |
3 | // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS= |
4 | // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile" |
5 | |
6 | typedef struct {int a;} ndrange_t; |
7 | // Diagnostic tests for different overloads of enqueue_kernel from Table 6.13.17.1 of OpenCL 2.0 Spec. |
8 | kernel void enqueue_kernel_tests() { |
9 | queue_t default_queue; |
10 | unsigned flags = 0; |
11 | QUALS ndrange_t ndrange; |
12 | clk_event_t evt; |
13 | clk_event_t event_wait_list; |
14 | clk_event_t event_wait_list2[] = {evt, evt}; |
15 | void *vptr; |
16 | |
17 | // Testing the first overload type |
18 | enqueue_kernel(default_queue, flags, ndrange, ^(void) { |
19 | return 0; |
20 | }); |
21 | |
22 | enqueue_kernel(vptr, flags, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'queue_t' argument type}} |
23 | return 0; |
24 | }); |
25 | |
26 | enqueue_kernel(default_queue, vptr, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'kernel_enqueue_flags_t' (i.e. uint) argument type}} |
27 | return 0; |
28 | }); |
29 | |
30 | enqueue_kernel(default_queue, flags, vptr, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'ndrange_t' argument type}} |
31 | return 0; |
32 | }); |
33 | |
34 | enqueue_kernel(default_queue, flags, ndrange, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}} |
35 | |
36 | enqueue_kernel(default_queue, flags, ndrange, ^(int i) { // expected-error{{blocks with parameters are not accepted in this prototype of enqueue_kernel call}} |
37 | return 0; |
38 | }); |
39 | |
40 | // Testing the second overload type |
41 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, ^(void) { |
42 | return 0; |
43 | }); |
44 | |
45 | enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0, ^(void) { |
46 | return 0; |
47 | }); |
48 | |
49 | enqueue_kernel(default_queue, flags, ndrange, vptr, &event_wait_list, &evt, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected integer argument type}} |
50 | return 0; |
51 | }); |
52 | |
53 | enqueue_kernel(default_queue, flags, ndrange, 1, vptr, &evt, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}} |
54 | { |
55 | return 0; |
56 | }); |
57 | |
58 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, vptr, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}} |
59 | { |
60 | return 0; |
61 | }); |
62 | |
63 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}} |
64 | |
65 | // Testing the third overload type |
66 | enqueue_kernel(default_queue, flags, ndrange, |
67 | ^(local void *a, local void *b) { |
68 | return 0; |
69 | }, |
70 | 1024, 1024); |
71 | |
72 | enqueue_kernel(default_queue, flags, ndrange, |
73 | ^(local void *a, local void *b) { |
74 | return 0; |
75 | }, |
76 | 1024L, 1024); |
77 | |
78 | enqueue_kernel(default_queue, flags, ndrange, |
79 | ^(local void *a, local void *b) { |
80 | return 0; |
81 | }, |
82 | 1024, 4294967296L); |
83 | #ifdef B32 |
84 | // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 4294967296 to 0}} |
85 | #endif |
86 | |
87 | char c; |
88 | enqueue_kernel(default_queue, flags, ndrange, |
89 | ^(local void *a, local void *b) { |
90 | return 0; |
91 | }, |
92 | c, 1024L); |
93 | #ifdef WCONV |
94 | // expected-warning-re@-2{{implicit conversion changes signedness: 'char' to 'unsigned {{int|long}}'}} |
95 | #endif |
96 | #define UINT_MAX 4294967295 |
97 | |
98 | enqueue_kernel(default_queue, flags, ndrange, |
99 | ^(local void *a, local void *b) { |
100 | return 0; |
101 | }, |
102 | sizeof(int), sizeof(int) * UINT_MAX); |
103 | #ifdef B32 |
104 | // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 17179869180 to 4294967292}} |
105 | #endif |
106 | |
107 | typedef void (^bl_A_t)(local void *); |
108 | |
109 | const bl_A_t block_A = (bl_A_t) ^ (local void *a) {}; |
110 | |
111 | enqueue_kernel(default_queue, flags, ndrange, block_A, 1024); |
112 | |
113 | typedef void (^bl_B_t)(local void *, local int *); |
114 | |
115 | const bl_B_t block_B = (bl_B_t) ^ (local void *a, local int *b) {}; |
116 | |
117 | enqueue_kernel(default_queue, flags, ndrange, block_B, 1024, 1024); // expected-error{{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
118 | |
119 | enqueue_kernel(default_queue, flags, ndrange, // expected-error{{mismatch in number of block parameters and local size arguments passed}} |
120 | ^(local void *a, local void *b) { |
121 | return 0; |
122 | }, |
123 | 1024); |
124 | |
125 | float illegal_mem_size = (float)0.5f; |
126 | enqueue_kernel(default_queue, flags, ndrange, |
127 | ^(local void *a, local void *b) { |
128 | return 0; |
129 | }, |
130 | illegal_mem_size, illegal_mem_size); // expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}} expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}} |
131 | |
132 | enqueue_kernel(default_queue, flags, ndrange, |
133 | ^(local void *a, local void *b) { |
134 | return 0; |
135 | }, |
136 | illegal_mem_size, 1024); // expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}} |
137 | |
138 | // Testing the forth overload type |
139 | enqueue_kernel(default_queue, flags, ndrange, 1, event_wait_list2, &evt, |
140 | ^(local void *a, local void *b) { |
141 | return 0; |
142 | }, |
143 | 1024, 1024); |
144 | |
145 | enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0, |
146 | ^(local void *a, local void *b) { |
147 | return 0; |
148 | }, |
149 | 1024, 1024); |
150 | |
151 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, // expected-error{{mismatch in number of block parameters and local size arguments passed}} |
152 | ^(local void *a, local void *b) { |
153 | return 0; |
154 | }, |
155 | 1024, 1024, 1024); |
156 | |
157 | // More random misc cases that can't be deduced |
158 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}} |
159 | |
160 | enqueue_kernel(default_queue, flags, ndrange, 1, 1); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}} |
161 | } |
162 | |
163 | // Diagnostic tests for get_kernel_work_group_size and allowed block parameter types in dynamic parallelism. |
164 | kernel void work_group_size_tests() { |
165 | void (^const block_A)(void) = ^{ |
166 | return; |
167 | }; |
168 | void (^const block_B)(int) = ^(int a) { |
169 | return; |
170 | }; |
171 | void (^const block_C)(local void *) = ^(local void *a) { |
172 | return; |
173 | }; |
174 | void (^const block_D)(local int *) = ^(local int *a) { |
175 | return; |
176 | }; |
177 | |
178 | unsigned size = get_kernel_work_group_size(block_A); |
179 | size = get_kernel_work_group_size(block_C); |
180 | size = get_kernel_work_group_size(^(local void *a) { |
181 | return; |
182 | }); |
183 | size = get_kernel_work_group_size(^(local int *a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
184 | return; |
185 | }); |
186 | size = get_kernel_work_group_size(block_B); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
187 | size = get_kernel_work_group_size(block_D); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
188 | size = get_kernel_work_group_size(^(int a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
189 | return; |
190 | }); |
191 | size = get_kernel_work_group_size(); // expected-error {{too few arguments to function call, expected 1, have 0}} |
192 | size = get_kernel_work_group_size(1); // expected-error{{expected block argument}} |
193 | size = get_kernel_work_group_size(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}} |
194 | |
195 | size = get_kernel_preferred_work_group_size_multiple(block_A); |
196 | size = get_kernel_preferred_work_group_size_multiple(block_C); |
197 | size = get_kernel_preferred_work_group_size_multiple(^(local void *a) { |
198 | return; |
199 | }); |
200 | size = get_kernel_preferred_work_group_size_multiple(^(local int *a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
201 | return; |
202 | }); |
203 | size = get_kernel_preferred_work_group_size_multiple(^(int a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
204 | return; |
205 | }); |
206 | size = get_kernel_preferred_work_group_size_multiple(block_B); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
207 | size = get_kernel_preferred_work_group_size_multiple(block_D); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}} |
208 | size = get_kernel_preferred_work_group_size_multiple(); // expected-error {{too few arguments to function call, expected 1, have 0}} |
209 | size = get_kernel_preferred_work_group_size_multiple(1); // expected-error{{expected block argument}} |
210 | size = get_kernel_preferred_work_group_size_multiple(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}} |
211 | } |
212 | |
213 | #pragma OPENCL EXTENSION cl_khr_subgroups : enable |
214 | |
215 | kernel void foo(global unsigned int *buf) |
216 | { |
217 | ndrange_t n; |
218 | buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); |
219 | buf[0] = get_kernel_max_sub_group_size_for_ndrange(0, ^(){}); // expected-error{{illegal call to 'get_kernel_max_sub_group_size_for_ndrange', expected 'ndrange_t' argument type}} |
220 | buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, 1); // expected-error{{illegal call to 'get_kernel_max_sub_group_size_for_ndrange', expected block argument type}} |
221 | } |
222 | |
223 | kernel void bar(global unsigned int *buf) |
224 | { |
225 | __private ndrange_t n; |
226 | buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); |
227 | buf[0] = get_kernel_sub_group_count_for_ndrange(0, ^(){}); // expected-error{{illegal call to 'get_kernel_sub_group_count_for_ndrange', expected 'ndrange_t' argument type}} |
228 | buf[0] = get_kernel_sub_group_count_for_ndrange(n, 1); // expected-error{{illegal call to 'get_kernel_sub_group_count_for_ndrange', expected block argument type}} |
229 | } |
230 | |
231 | #pragma OPENCL EXTENSION cl_khr_subgroups : disable |
232 | |
233 | kernel void foo1(global unsigned int *buf) |
234 | { |
235 | ndrange_t n; |
236 | buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' requires cl_khr_subgroups extension to be enabled}} |
237 | } |
238 | |
239 | kernel void bar1(global unsigned int *buf) |
240 | { |
241 | ndrange_t n; |
242 | buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires cl_khr_subgroups extension to be enabled}} |
243 | } |
244 | |