1 | // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL2.0 |
2 | // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL2.0 |
3 | // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL2.0 |
4 | // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=c++ |
5 | // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=c++ |
6 | // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=c++ |
7 | |
8 | /* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to |
9 | * different address spaces, mainly described in Sections 6.5.5 and 6.5.6. |
10 | * |
11 | * It adds notion of overlapping address spaces. The main differention is that |
12 | * an unnamed address space is added, called '__generic'. Pointers to the |
13 | * generic address space can be interchangabley used with pointers to any |
14 | * other address space except for __constant address space (Section 6.5.5). |
15 | * |
16 | * Based on this there are 3 sets of tests: __generic, named (__global in this |
17 | * case), and __constant, that should cover all program paths for CL address |
18 | * space conversions used in initialisations, assignments, casts, comparisons |
19 | * and arithmetic operations. |
20 | */ |
21 | |
22 | #ifdef GENERIC |
23 | #define AS __generic |
24 | #define AS_COMP __local |
25 | #define AS_INCOMP __constant |
26 | #endif |
27 | |
28 | #ifdef GLOBAL |
29 | #define AS __global |
30 | #define AS_COMP __global |
31 | #define AS_INCOMP __local |
32 | #endif |
33 | |
34 | #ifdef CONSTANT |
35 | #define AS __constant |
36 | #define AS_COMP __constant |
37 | #define AS_INCOMP __global |
38 | #endif |
39 | |
40 | void f_glob(__global int *arg_glob) {} |
41 | #ifndef GLOBAL |
42 | #if !__OPENCL_CPP_VERSION__ |
43 | // expected-note@-3{{passing argument to parameter 'arg_glob' here}} |
44 | #else |
45 | // expected-note-re@-5{{candidate function not viable: address space mismatch in 1st argument ('__{{generic|constant}} int *'), parameter type must be '__global int *'}} |
46 | #endif |
47 | #endif |
48 | |
49 | void f_loc(__local int *arg_loc) {} |
50 | #if !__OPENCL_CPP_VERSION__ |
51 | // expected-note@-2{{passing argument to parameter 'arg_loc' here}} |
52 | #else |
53 | // expected-note-re@-4{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic|constant}} int *'), parameter type must be '__local int *'}} |
54 | #endif |
55 | |
56 | void f_const(__constant int *arg_const) {} |
57 | #ifndef CONSTANT |
58 | #if !__OPENCL_CPP_VERSION__ |
59 | // expected-note@-3{{passing argument to parameter 'arg_const' here}} |
60 | #else |
61 | // expected-note-re@-5{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic}} int *'), parameter type must be '__constant int *'}} |
62 | #endif |
63 | #endif |
64 | |
65 | void f_priv(__private int *arg_priv) {} |
66 | #if !__OPENCL_CPP_VERSION__ |
67 | // expected-note@-2{{passing argument to parameter 'arg_priv' here}} |
68 | #else |
69 | // expected-note-re@-4{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic|constant}} int *'), parameter type must be 'int *'}} |
70 | #endif |
71 | |
72 | void f_gen(__generic int *arg_gen) {} |
73 | #ifdef CONSTANT |
74 | #if !__OPENCL_CPP_VERSION__ |
75 | // expected-note@-3{{passing argument to parameter 'arg_gen' here}} |
76 | #else |
77 | // expected-note@-5{{candidate function not viable: address space mismatch in 1st argument ('__constant int *'), parameter type must be '__generic int *'}} |
78 | #endif |
79 | #endif |
80 | |
81 | void test_conversion(__global int *arg_glob, __local int *arg_loc, |
82 | __constant int *arg_const, __private int *arg_priv, |
83 | __generic int *arg_gen) { |
84 | |
85 | AS int *var_init1 = arg_glob; |
86 | #ifdef CONSTANT |
87 | #if !__OPENCL_CPP_VERSION__ |
88 | // expected-error@-3{{initializing '__constant int *' with an expression of type '__global int *' changes address space of pointer}} |
89 | #else |
90 | // expected-error@-5{{cannot initialize a variable of type '__constant int *' with an lvalue of type '__global int *'}} |
91 | #endif |
92 | #endif |
93 | |
94 | AS int *var_init2 = arg_loc; |
95 | #ifndef GENERIC |
96 | #if !__OPENCL_CPP_VERSION__ |
97 | // expected-error-re@-3{{initializing '__{{global|constant}} int *' with an expression of type '__local int *' changes address space of pointer}} |
98 | #else |
99 | // expected-error-re@-5{{cannot initialize a variable of type '__{{global|constant}} int *' with an lvalue of type '__local int *'}} |
100 | #endif |
101 | #endif |
102 | |
103 | AS int *var_init3 = arg_const; |
104 | #ifndef CONSTANT |
105 | #if !__OPENCL_CPP_VERSION__ |
106 | // expected-error-re@-3{{initializing '__{{global|generic}} int *' with an expression of type '__constant int *' changes address space of pointer}} |
107 | #else |
108 | // expected-error-re@-5{{cannot initialize a variable of type '__{{global|generic}} int *' with an lvalue of type '__constant int *'}} |
109 | #endif |
110 | #endif |
111 | |
112 | AS int *var_init4 = arg_priv; |
113 | #ifndef GENERIC |
114 | #if !__OPENCL_CPP_VERSION__ |
115 | // expected-error-re@-3{{initializing '__{{global|constant}} int *' with an expression of type 'int *' changes address space of pointer}} |
116 | #else |
117 | // expected-error-re@-5{{cannot initialize a variable of type '__{{global|constant}} int *' with an lvalue of type 'int *'}} |
118 | #endif |
119 | #endif |
120 | |
121 | AS int *var_init5 = arg_gen; |
122 | #ifndef GENERIC |
123 | #if !__OPENCL_CPP_VERSION__ |
124 | // expected-error-re@-3{{initializing '__{{global|constant}} int *' with an expression of type '__generic int *' changes address space of pointer}} |
125 | #else |
126 | // expected-error-re@-5{{cannot initialize a variable of type '__{{global|constant}} int *' with an lvalue of type '__generic int *'}} |
127 | #endif |
128 | #endif |
129 | |
130 | AS int *var_cast1 = (AS int *)arg_glob; |
131 | #ifdef CONSTANT |
132 | #if !__OPENCL_CPP_VERSION__ |
133 | // expected-error@-3{{casting '__global int *' to type '__constant int *' changes address space of pointer}} |
134 | #else |
135 | // expected-error@-5{{C-style cast from '__global int *' to '__constant int *' converts between mismatching address spaces}} |
136 | #endif |
137 | #endif |
138 | |
139 | AS int *var_cast2 = (AS int *)arg_loc; |
140 | #ifndef GENERIC |
141 | #if !__OPENCL_CPP_VERSION__ |
142 | // expected-error-re@-3{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}} |
143 | #else |
144 | // expected-error-re@-5{{C-style cast from '__local int *' to '__{{global|constant}} int *' converts between mismatching address spaces}} |
145 | #endif |
146 | #endif |
147 | |
148 | AS int *var_cast3 = (AS int *)arg_const; |
149 | #ifndef CONSTANT |
150 | #if !__OPENCL_CPP_VERSION__ |
151 | // expected-error-re@-3{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}} |
152 | #else |
153 | // expected-error-re@-5{{C-style cast from '__constant int *' to '__{{global|generic}} int *' converts between mismatching address spaces}} |
154 | #endif |
155 | #endif |
156 | |
157 | AS int *var_cast4 = (AS int *)arg_priv; |
158 | #ifndef GENERIC |
159 | #if !__OPENCL_CPP_VERSION__ |
160 | // expected-error-re@-3{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}} |
161 | #else |
162 | // expected-error-re@-5{{C-style cast from 'int *' to '__{{global|constant}} int *' converts between mismatching address spaces}} |
163 | #endif |
164 | #endif |
165 | |
166 | AS int *var_cast5 = (AS int *)arg_gen; |
167 | #ifdef CONSTANT |
168 | #if !__OPENCL_CPP_VERSION__ |
169 | // expected-error@-3{{casting '__generic int *' to type '__constant int *' changes address space of pointer}} |
170 | #else |
171 | // expected-error@-5{{C-style cast from '__generic int *' to '__constant int *' converts between mismatching address spaces}} |
172 | #endif |
173 | #endif |
174 | |
175 | AS int *var_impl; |
176 | var_impl = arg_glob; |
177 | #ifdef CONSTANT |
178 | #if !__OPENCL_CPP_VERSION__ |
179 | // expected-error@-3{{assigning '__global int *' to '__constant int *' changes address space of pointer}} |
180 | #else |
181 | // expected-error@-5{{assigning to '__constant int *' from incompatible type '__global int *'}} |
182 | #endif |
183 | #endif |
184 | |
185 | var_impl = arg_loc; |
186 | #ifndef GENERIC |
187 | #if !__OPENCL_CPP_VERSION__ |
188 | // expected-error-re@-3{{assigning '__local int *' to '__{{global|constant}} int *' changes address space of pointer}} |
189 | #else |
190 | // expected-error-re@-5{{assigning to '__{{global|constant}} int *' from incompatible type '__local int *'}} |
191 | #endif |
192 | #endif |
193 | |
194 | var_impl = arg_const; |
195 | #ifndef CONSTANT |
196 | #if !__OPENCL_CPP_VERSION__ |
197 | // expected-error-re@-3{{assigning '__constant int *' to '__{{global|generic}} int *' changes address space of pointer}} |
198 | #else |
199 | // expected-error-re@-5{{assigning to '__{{global|generic}} int *' from incompatible type '__constant int *'}} |
200 | #endif |
201 | #endif |
202 | |
203 | var_impl = arg_priv; |
204 | #ifndef GENERIC |
205 | #if !__OPENCL_CPP_VERSION__ |
206 | // expected-error-re@-3{{assigning 'int *' to '__{{global|constant}} int *' changes address space of pointer}} |
207 | #else |
208 | // expected-error-re@-5{{assigning to '__{{global|constant}} int *' from incompatible type 'int *'}} |
209 | #endif |
210 | #endif |
211 | |
212 | var_impl = arg_gen; |
213 | #ifndef GENERIC |
214 | #if !__OPENCL_CPP_VERSION__ |
215 | // expected-error-re@-3{{assigning '__generic int *' to '__{{global|constant}} int *' changes address space of pointer}} |
216 | #else |
217 | // expected-error-re@-5{{assigning to '__{{global|constant}} int *' from incompatible type '__generic int *'}} |
218 | #endif |
219 | #endif |
220 | |
221 | var_cast1 = (AS int *)arg_glob; |
222 | #ifdef CONSTANT |
223 | #if !__OPENCL_CPP_VERSION__ |
224 | // expected-error@-3{{casting '__global int *' to type '__constant int *' changes address space of pointer}} |
225 | #else |
226 | // expected-error@-5{{C-style cast from '__global int *' to '__constant int *' converts between mismatching address spaces}} |
227 | #endif |
228 | #endif |
229 | |
230 | var_cast2 = (AS int *)arg_loc; |
231 | #ifndef GENERIC |
232 | #if !__OPENCL_CPP_VERSION__ |
233 | // expected-error-re@-3{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}} |
234 | #else |
235 | // expected-error-re@-5{{C-style cast from '__local int *' to '__{{global|constant}} int *' converts between mismatching address spaces}} |
236 | #endif |
237 | #endif |
238 | |
239 | var_cast3 = (AS int *)arg_const; |
240 | #ifndef CONSTANT |
241 | #if !__OPENCL_CPP_VERSION__ |
242 | // expected-error-re@-3{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}} |
243 | #else |
244 | // expected-error-re@-5{{C-style cast from '__constant int *' to '__{{global|generic}} int *' converts between mismatching address spaces}} |
245 | #endif |
246 | #endif |
247 | |
248 | var_cast4 = (AS int *)arg_priv; |
249 | #ifndef GENERIC |
250 | #if !__OPENCL_CPP_VERSION__ |
251 | // expected-error-re@-3{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}} |
252 | #else |
253 | // expected-error-re@-5{{C-style cast from 'int *' to '__{{global|constant}} int *' converts between mismatching address spaces}} |
254 | #endif |
255 | #endif |
256 | |
257 | var_cast5 = (AS int *)arg_gen; |
258 | #ifdef CONSTANT |
259 | #if !__OPENCL_CPP_VERSION__ |
260 | // expected-error@-3{{casting '__generic int *' to type '__constant int *' changes address space of pointer}} |
261 | #else |
262 | // expected-error@-5{{C-style cast from '__generic int *' to '__constant int *' converts between mismatching address spaces}} |
263 | #endif |
264 | #endif |
265 | |
266 | AS int *var_cmp; |
267 | int b = var_cmp != arg_glob; |
268 | #ifdef CONSTANT |
269 | #if !__OPENCL_CPP_VERSION__ |
270 | // expected-error@-3{{comparison between ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} |
271 | #else |
272 | // expected-error@-5{{comparison of distinct pointer types ('__constant int *' and '__global int *')}} |
273 | #endif |
274 | #endif |
275 | |
276 | b = var_cmp != arg_loc; |
277 | #ifndef GENERIC |
278 | #if !__OPENCL_CPP_VERSION__ |
279 | // expected-error-re@-3{{comparison between ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} |
280 | #else |
281 | // expected-error-re@-5{{comparison of distinct pointer types ('__{{global|constant}} int *' and '__local int *')}} |
282 | #endif |
283 | #endif |
284 | |
285 | b = var_cmp == arg_const; |
286 | #ifndef CONSTANT |
287 | #if !__OPENCL_CPP_VERSION__ |
288 | // expected-error-re@-3{{comparison between ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} |
289 | #else |
290 | // expected-error-re@-5{{comparison of distinct pointer types ('__{{global|generic}} int *' and '__constant int *')}} |
291 | #endif |
292 | #endif |
293 | |
294 | b = var_cmp <= arg_priv; |
295 | #ifndef GENERIC |
296 | #if !__OPENCL_CPP_VERSION__ |
297 | // expected-error-re@-3{{comparison between ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} |
298 | #else |
299 | // expected-error-re@-5{{comparison of distinct pointer types ('__{{global|constant}} int *' and 'int *')}} |
300 | #endif |
301 | #endif |
302 | |
303 | b = var_cmp >= arg_gen; |
304 | #ifdef CONSTANT |
305 | #if !__OPENCL_CPP_VERSION__ |
306 | // expected-error@-3{{comparison between ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} |
307 | #else |
308 | // expected-error@-5{{comparison of distinct pointer types ('__constant int *' and '__generic int *')}} |
309 | #endif |
310 | #endif |
311 | |
312 | AS int *var_sub; |
313 | b = var_sub - arg_glob; |
314 | #ifdef CONSTANT |
315 | // expected-error@-2{{arithmetic operation with operands of type ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} |
316 | #endif |
317 | |
318 | b = var_sub - arg_loc; |
319 | #ifndef GENERIC |
320 | // expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} |
321 | #endif |
322 | |
323 | b = var_sub - arg_const; |
324 | #ifndef CONSTANT |
325 | // expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} |
326 | #endif |
327 | |
328 | b = var_sub - arg_priv; |
329 | #ifndef GENERIC |
330 | // expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} |
331 | #endif |
332 | |
333 | b = var_sub - arg_gen; |
334 | #ifdef CONSTANT |
335 | // expected-error@-2{{arithmetic operation with operands of type ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} |
336 | #endif |
337 | |
338 | f_glob(var_sub); |
339 | #ifndef GLOBAL |
340 | #if !__OPENCL_CPP_VERSION__ |
341 | // expected-error-re@-3{{passing '__{{constant|generic}} int *' to parameter of type '__global int *' changes address space of pointer}} |
342 | #else |
343 | // expected-error@-5{{no matching function for call to 'f_glob'}} |
344 | #endif |
345 | #endif |
346 | |
347 | f_loc(var_sub); |
348 | #if !__OPENCL_CPP_VERSION__ |
349 | // expected-error-re@-2{{passing '__{{global|constant|generic}} int *' to parameter of type '__local int *' changes address space of pointer}} |
350 | #else |
351 | // expected-error@-4{{no matching function for call to 'f_loc'}} |
352 | #endif |
353 | |
354 | f_const(var_sub); |
355 | #ifndef CONSTANT |
356 | #if !__OPENCL_CPP_VERSION__ |
357 | // expected-error-re@-3{{passing '__{{global|generic}} int *' to parameter of type '__constant int *' changes address space of pointer}} |
358 | #else |
359 | // expected-error@-5{{no matching function for call to 'f_const'}} |
360 | #endif |
361 | #endif |
362 | |
363 | f_priv(var_sub); |
364 | #if !__OPENCL_CPP_VERSION__ |
365 | // expected-error-re@-2{{passing '__{{global|constant|generic}} int *' to parameter of type 'int *' changes address space of pointer}} |
366 | #else |
367 | // expected-error@-4{{no matching function for call to 'f_priv'}} |
368 | #endif |
369 | |
370 | f_gen(var_sub); |
371 | #ifdef CONSTANT |
372 | #if !__OPENCL_CPP_VERSION__ |
373 | // expected-error@-3{{passing '__constant int *' to parameter of type '__generic int *' changes address space of pointer}} |
374 | #else |
375 | // expected-error@-5{{no matching function for call to 'f_gen'}} |
376 | #endif |
377 | #endif |
378 | } |
379 | |
380 | void test_ternary() { |
381 | AS int *var_cond; |
382 | __generic int *var_gen; |
383 | __global int *var_glob; |
384 | var_gen = 0 ? var_cond : var_glob; |
385 | #ifdef CONSTANT |
386 | #if !__OPENCL_CPP_VERSION__ |
387 | // expected-error@-3{{conditional operator with the second and third operands of type ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} |
388 | #else |
389 | // expected-error@-5{{incompatible operand types ('__constant int *' and '__global int *')}} |
390 | #endif |
391 | #endif |
392 | |
393 | __local int *var_loc; |
394 | var_gen = 0 ? var_cond : var_loc; |
395 | #ifndef GENERIC |
396 | #if !__OPENCL_CPP_VERSION__ |
397 | // expected-error-re@-3{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} |
398 | #else |
399 | // expected-error-re@-5{{incompatible operand types ('__{{global|constant}} int *' and '__local int *')}} |
400 | #endif |
401 | #endif |
402 | |
403 | __constant int *var_const; |
404 | var_cond = 0 ? var_cond : var_const; |
405 | #ifndef CONSTANT |
406 | #if !__OPENCL_CPP_VERSION__ |
407 | // expected-error-re@-3{{conditional operator with the second and third operands of type ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} |
408 | #else |
409 | // expected-error-re@-5{{incompatible operand types ('__{{global|generic}} int *' and '__constant int *')}} |
410 | #endif |
411 | #endif |
412 | |
413 | __private int *var_priv; |
414 | var_gen = 0 ? var_cond : var_priv; |
415 | #ifndef GENERIC |
416 | #if !__OPENCL_CPP_VERSION__ |
417 | // expected-error-re@-3{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} |
418 | #else |
419 | // expected-error-re@-5{{incompatible operand types ('__{{global|constant}} int *' and 'int *')}} |
420 | #endif |
421 | #endif |
422 | |
423 | var_gen = 0 ? var_cond : var_gen; |
424 | #ifdef CONSTANT |
425 | #if !__OPENCL_CPP_VERSION__ |
426 | // expected-error@-3{{conditional operator with the second and third operands of type ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} |
427 | #else |
428 | // expected-error@-5{{incompatible operand types ('__constant int *' and '__generic int *')}} |
429 | #endif |
430 | #endif |
431 | |
432 | void *var_void_gen; |
433 | __global char *var_glob_ch; |
434 | var_void_gen = 0 ? var_cond : var_glob_ch; |
435 | #if __OPENCL_CPP_VERSION__ |
436 | // expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__global char *')}} |
437 | #else |
438 | #ifdef CONSTANT |
439 | // expected-error@-5{{conditional operator with the second and third operands of type ('__constant int *' and '__global char *') which are pointers to non-overlapping address spaces}} |
440 | #else |
441 | // expected-warning-re@-7{{pointer type mismatch ('__{{global|generic}} int *' and '__global char *')}} |
442 | #endif |
443 | #endif |
444 | |
445 | __local char *var_loc_ch; |
446 | var_void_gen = 0 ? var_cond : var_loc_ch; |
447 | #if __OPENCL_CPP_VERSION__ |
448 | // expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__local char *')}} |
449 | #else |
450 | #ifndef GENERIC |
451 | // expected-error-re@-5{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and '__local char *') which are pointers to non-overlapping address spaces}} |
452 | #else |
453 | // expected-warning@-7{{pointer type mismatch ('__generic int *' and '__local char *')}} |
454 | #endif |
455 | #endif |
456 | |
457 | __constant void *var_void_const; |
458 | __constant char *var_const_ch; |
459 | var_void_const = 0 ? var_cond : var_const_ch; |
460 | #if __OPENCL_CPP_VERSION__ |
461 | // expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__constant char *')}} |
462 | #else |
463 | #ifndef CONSTANT |
464 | // expected-error-re@-5{{conditional operator with the second and third operands of type ('__{{global|generic}} int *' and '__constant char *') which are pointers to non-overlapping address spaces}} |
465 | #else |
466 | // expected-warning@-7{{pointer type mismatch ('__constant int *' and '__constant char *')}} |
467 | #endif |
468 | #endif |
469 | |
470 | __private char *var_priv_ch; |
471 | var_void_gen = 0 ? var_cond : var_priv_ch; |
472 | #if __OPENCL_CPP_VERSION__ |
473 | // expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and 'char *')}} |
474 | #else |
475 | #ifndef GENERIC |
476 | // expected-error-re@-5{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and 'char *') which are pointers to non-overlapping address spaces}} |
477 | #else |
478 | // expected-warning@-7{{pointer type mismatch ('__generic int *' and 'char *')}} |
479 | #endif |
480 | #endif |
481 | |
482 | __generic char *var_gen_ch; |
483 | var_void_gen = 0 ? var_cond : var_gen_ch; |
484 | #if __OPENCL_CPP_VERSION__ |
485 | // expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__generic char *')}} |
486 | #else |
487 | #ifdef CONSTANT |
488 | // expected-error@-5{{conditional operator with the second and third operands of type ('__constant int *' and '__generic char *') which are pointers to non-overlapping address spaces}} |
489 | #else |
490 | // expected-warning-re@-7{{pointer type mismatch ('__{{global|generic}} int *' and '__generic char *')}} |
491 | #endif |
492 | #endif |
493 | } |
494 | |
495 | void test_pointer_chains() { |
496 | AS int *AS *var_as_as_int; |
497 | AS int *AS_COMP *var_asc_as_int; |
498 | AS_INCOMP int *AS_COMP *var_asc_asn_int; |
499 | AS_COMP int *AS_COMP *var_asc_asc_int; |
500 | |
501 | // Case 1: |
502 | // * address spaces of corresponded most outer pointees overlaps, their canonical types are equal |
503 | // * CVR, address spaces and canonical types of the rest of pointees are equivalent. |
504 | var_as_as_int = 0 ? var_as_as_int : var_asc_as_int; |
505 | #if __OPENCL_CPP_VERSION__ |
506 | #ifdef GENERIC |
507 | // expected-error@-3{{incompatible operand types ('__generic int *__generic *' and '__generic int *__local *')}} |
508 | #endif |
509 | #endif |
510 | // Case 2: Corresponded inner pointees has non-overlapping address spaces. |
511 | var_as_as_int = 0 ? var_as_as_int : var_asc_asn_int; |
512 | #if !__OPENCL_CPP_VERSION__ |
513 | // expected-warning-re@-2{{pointer type mismatch ('__{{(generic|global|constant)}} int *__{{(generic|global|constant)}} *' and '__{{(local|global|constant)}} int *__{{(constant|local|global)}} *')}} |
514 | #else |
515 | // expected-error-re@-4{{incompatible operand types ('__{{(generic|global|constant)}} int *__{{(generic|global|constant)}} *' and '__{{(local|global|constant)}} int *__{{(constant|local|global)}} *')}} |
516 | #endif |
517 | |
518 | // Case 3: Corresponded inner pointees has overlapping but not equivalent address spaces. |
519 | #ifdef GENERIC |
520 | var_as_as_int = 0 ? var_as_as_int : var_asc_asc_int; |
521 | #if !__OPENCL_CPP_VERSION__ |
522 | // expected-warning-re@-2{{pointer type mismatch ('__{{(generic|global|constant)}} int *__{{(generic|global|constant)}} *' and '__{{(local|global|constant)}} int *__{{(local|global|constant)}} *')}} |
523 | #else |
524 | // expected-error-re@-4{{incompatible operand types ('__{{generic|global|constant}} int *__{{generic|global|constant}} *' and '__{{local|global|constant}} int *__{{local|global|constant}} *')}} |
525 | #endif |
526 | #endif |
527 | } |
528 | |