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