• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6typedef 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.
8kernel 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: '__private 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  enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few arguments to function call, expected at least 4, have 3}}
163}
164
165// Diagnostic tests for get_kernel_work_group_size and allowed block parameter types in dynamic parallelism.
166kernel void work_group_size_tests() {
167  void (^const block_A)(void) = ^{
168    return;
169  };
170  void (^const block_B)(int) = ^(int a) {
171    return;
172  };
173  void (^const block_C)(local void *) = ^(local void *a) {
174    return;
175  };
176  void (^const block_D)(local int *) = ^(local int *a) {
177    return;
178  };
179
180  unsigned size = get_kernel_work_group_size(block_A);
181  size = get_kernel_work_group_size(block_C);
182  size = get_kernel_work_group_size(^(local void *a) {
183    return;
184  });
185  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*'}}
186    return;
187  });
188  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*'}}
189  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*'}}
190  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*'}}
191    return;
192  });
193  size = get_kernel_work_group_size();          // expected-error {{too few arguments to function call, expected 1, have 0}}
194  size = get_kernel_work_group_size(1);         // expected-error{{expected block argument}}
195  size = get_kernel_work_group_size(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}}
196
197  size = get_kernel_preferred_work_group_size_multiple(block_A);
198  size = get_kernel_preferred_work_group_size_multiple(block_C);
199  size = get_kernel_preferred_work_group_size_multiple(^(local void *a) {
200    return;
201  });
202  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*'}}
203    return;
204  });
205  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*'}}
206    return;
207  });
208  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*'}}
209  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*'}}
210  size = get_kernel_preferred_work_group_size_multiple();          // expected-error {{too few arguments to function call, expected 1, have 0}}
211  size = get_kernel_preferred_work_group_size_multiple(1);         // expected-error{{expected block argument}}
212  size = get_kernel_preferred_work_group_size_multiple(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}}
213}
214
215#pragma OPENCL EXTENSION cl_khr_subgroups : enable
216
217kernel void foo(global unsigned int *buf)
218{
219  ndrange_t n;
220  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){});
221  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}}
222  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}}
223}
224
225kernel void bar(global unsigned int *buf)
226{
227  __private ndrange_t n;
228  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){});
229  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}}
230  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}}
231}
232
233#pragma OPENCL EXTENSION cl_khr_subgroups : disable
234
235kernel void foo1(global unsigned int *buf)
236{
237  ndrange_t n;
238  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}}
239}
240
241kernel void bar1(global unsigned int *buf)
242{
243  ndrange_t n;
244  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}}
245}
246