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