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