xref: /aosp_15_r20/external/clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL2.0
2*67e74705SXin Li// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL2.0
3*67e74705SXin Li// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL2.0
4*67e74705SXin Li
5*67e74705SXin Li/* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to
6*67e74705SXin Li*  different address spaces, mainly described in Sections 6.5.5 and 6.5.6.
7*67e74705SXin Li*
8*67e74705SXin Li*  It adds notion of overlapping address spaces. The main differention is that
9*67e74705SXin Li*  an unnamed address space is added, called '__generic'. Pointers to the
10*67e74705SXin Li*  generic address space can be interchangabley used with pointers to any
11*67e74705SXin Li*  other address space except for __constant address space (Section 6.5.5).
12*67e74705SXin Li*
13*67e74705SXin Li*  Based on this there are 3 sets of tests: __generic, named (__global in this
14*67e74705SXin Li*  case), and __constant, that should cover all program paths for CL address
15*67e74705SXin Li*  space conversions used in initialisations, assignments, casts, comparisons
16*67e74705SXin Li*  and arithmetic operations.
17*67e74705SXin Li*/
18*67e74705SXin Li
19*67e74705SXin Li#ifdef GENERIC
20*67e74705SXin Li#define AS generic
21*67e74705SXin Li#endif
22*67e74705SXin Li
23*67e74705SXin Li#ifdef GLOBAL
24*67e74705SXin Li#define AS global
25*67e74705SXin Li#endif
26*67e74705SXin Li
27*67e74705SXin Li#ifdef CONSTANT
28*67e74705SXin Li#define AS constant
29*67e74705SXin Li#endif
30*67e74705SXin Li
31*67e74705SXin Livoid f_glob(global int *arg_glob) {}
32*67e74705SXin Li#ifndef GLOBAL
33*67e74705SXin Li// expected-note@-2{{passing argument to parameter 'arg_glob' here}}
34*67e74705SXin Li#endif
35*67e74705SXin Li
36*67e74705SXin Livoid f_loc(local int *arg_loc) {
37*67e74705SXin Li} // expected-note@-1{{passing argument to parameter 'arg_loc' here}}
38*67e74705SXin Li
39*67e74705SXin Livoid f_const(constant int *arg_const) {}
40*67e74705SXin Li#ifndef CONSTANT
41*67e74705SXin Li// expected-note@-2{{passing argument to parameter 'arg_const' here}}
42*67e74705SXin Li#endif
43*67e74705SXin Li
44*67e74705SXin Livoid f_priv(private int *arg_priv) {
45*67e74705SXin Li} // expected-note@-1{{passing argument to parameter 'arg_priv' here}}
46*67e74705SXin Li
47*67e74705SXin Livoid f_gen(generic int *arg_gen) {}
48*67e74705SXin Li#ifdef CONSTANT
49*67e74705SXin Li// expected-note@-2{{passing argument to parameter 'arg_gen' here}}
50*67e74705SXin Li#endif
51*67e74705SXin Li
52*67e74705SXin Livoid test_conversion(global int *arg_glob, local int *arg_loc,
53*67e74705SXin Li                     constant int *arg_const, private int *arg_priv,
54*67e74705SXin Li                     generic int *arg_gen) {
55*67e74705SXin Li
56*67e74705SXin Li  AS int *var_init1 = arg_glob;
57*67e74705SXin Li#ifdef CONSTANT
58*67e74705SXin Li// expected-error@-2{{initializing '__constant int *' with an expression of type '__global int *' changes address space of pointer}}
59*67e74705SXin Li#endif
60*67e74705SXin Li
61*67e74705SXin Li  AS int *var_init2 = arg_loc;
62*67e74705SXin Li#ifndef GENERIC
63*67e74705SXin Li// expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type '__local int *' changes address space of pointer}}
64*67e74705SXin Li#endif
65*67e74705SXin Li
66*67e74705SXin Li  AS int *var_init3 = arg_const;
67*67e74705SXin Li#ifndef CONSTANT
68*67e74705SXin Li// expected-error-re@-2{{initializing '__{{global|generic}} int *' with an expression of type '__constant int *' changes address space of pointer}}
69*67e74705SXin Li#endif
70*67e74705SXin Li
71*67e74705SXin Li  AS int *var_init4 = arg_priv;
72*67e74705SXin Li#ifndef GENERIC
73*67e74705SXin Li// expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type 'int *' changes address space of pointer}}
74*67e74705SXin Li#endif
75*67e74705SXin Li
76*67e74705SXin Li  AS int *var_init5 = arg_gen;
77*67e74705SXin Li#ifndef GENERIC
78*67e74705SXin Li// expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type '__generic int *' changes address space of pointer}}
79*67e74705SXin Li#endif
80*67e74705SXin Li
81*67e74705SXin Li  AS int *var_cast1 = (AS int *)arg_glob;
82*67e74705SXin Li#ifdef CONSTANT
83*67e74705SXin Li// expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}}
84*67e74705SXin Li#endif
85*67e74705SXin Li
86*67e74705SXin Li  AS int *var_cast2 = (AS int *)arg_loc;
87*67e74705SXin Li#ifndef GENERIC
88*67e74705SXin Li// expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}}
89*67e74705SXin Li#endif
90*67e74705SXin Li
91*67e74705SXin Li  AS int *var_cast3 = (AS int *)arg_const;
92*67e74705SXin Li#ifndef CONSTANT
93*67e74705SXin Li// expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}}
94*67e74705SXin Li#endif
95*67e74705SXin Li
96*67e74705SXin Li  AS int *var_cast4 = (AS int *)arg_priv;
97*67e74705SXin Li#ifndef GENERIC
98*67e74705SXin Li// expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}}
99*67e74705SXin Li#endif
100*67e74705SXin Li
101*67e74705SXin Li  AS int *var_cast5 = (AS int *)arg_gen;
102*67e74705SXin Li#ifdef CONSTANT
103*67e74705SXin Li// expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}}
104*67e74705SXin Li#endif
105*67e74705SXin Li
106*67e74705SXin Li  AS int *var_impl;
107*67e74705SXin Li  var_impl = arg_glob;
108*67e74705SXin Li#ifdef CONSTANT
109*67e74705SXin Li// expected-error@-2{{assigning '__global int *' to '__constant int *' changes address space of pointer}}
110*67e74705SXin Li#endif
111*67e74705SXin Li
112*67e74705SXin Li  var_impl = arg_loc;
113*67e74705SXin Li#ifndef GENERIC
114*67e74705SXin Li// expected-error-re@-2{{assigning '__local int *' to '__{{global|constant}} int *' changes address space of pointer}}
115*67e74705SXin Li#endif
116*67e74705SXin Li
117*67e74705SXin Li  var_impl = arg_const;
118*67e74705SXin Li#ifndef CONSTANT
119*67e74705SXin Li// expected-error-re@-2{{assigning '__constant int *' to '__{{global|generic}} int *' changes address space of pointer}}
120*67e74705SXin Li#endif
121*67e74705SXin Li
122*67e74705SXin Li  var_impl = arg_priv;
123*67e74705SXin Li#ifndef GENERIC
124*67e74705SXin Li// expected-error-re@-2{{assigning 'int *' to '__{{global|constant}} int *' changes address space of pointer}}
125*67e74705SXin Li#endif
126*67e74705SXin Li
127*67e74705SXin Li  var_impl = arg_gen;
128*67e74705SXin Li#ifndef GENERIC
129*67e74705SXin Li// expected-error-re@-2{{assigning '__generic int *' to '__{{global|constant}} int *' changes address space of pointer}}
130*67e74705SXin Li#endif
131*67e74705SXin Li
132*67e74705SXin Li  var_cast1 = (AS int *)arg_glob;
133*67e74705SXin Li#ifdef CONSTANT
134*67e74705SXin Li// expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}}
135*67e74705SXin Li#endif
136*67e74705SXin Li
137*67e74705SXin Li  var_cast2 = (AS int *)arg_loc;
138*67e74705SXin Li#ifndef GENERIC
139*67e74705SXin Li// expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}}
140*67e74705SXin Li#endif
141*67e74705SXin Li
142*67e74705SXin Li  var_cast3 = (AS int *)arg_const;
143*67e74705SXin Li#ifndef CONSTANT
144*67e74705SXin Li// expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}}
145*67e74705SXin Li#endif
146*67e74705SXin Li
147*67e74705SXin Li  var_cast4 = (AS int *)arg_priv;
148*67e74705SXin Li#ifndef GENERIC
149*67e74705SXin Li// expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}}
150*67e74705SXin Li#endif
151*67e74705SXin Li
152*67e74705SXin Li  var_cast5 = (AS int *)arg_gen;
153*67e74705SXin Li#ifdef CONSTANT
154*67e74705SXin Li// expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}}
155*67e74705SXin Li#endif
156*67e74705SXin Li
157*67e74705SXin Li  AS int *var_cmp;
158*67e74705SXin Li  int b = var_cmp != arg_glob;
159*67e74705SXin Li#ifdef CONSTANT
160*67e74705SXin Li// expected-error@-2{{comparison between  ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}}
161*67e74705SXin Li#endif
162*67e74705SXin Li
163*67e74705SXin Li  b = var_cmp != arg_loc;
164*67e74705SXin Li#ifndef GENERIC
165*67e74705SXin Li// expected-error-re@-2{{comparison between  ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}}
166*67e74705SXin Li#endif
167*67e74705SXin Li
168*67e74705SXin Li  b = var_cmp == arg_const;
169*67e74705SXin Li#ifndef CONSTANT
170*67e74705SXin Li// expected-error-re@-2{{comparison between  ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}}
171*67e74705SXin Li#endif
172*67e74705SXin Li
173*67e74705SXin Li  b = var_cmp <= arg_priv;
174*67e74705SXin Li#ifndef GENERIC
175*67e74705SXin Li// expected-error-re@-2{{comparison between  ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}}
176*67e74705SXin Li#endif
177*67e74705SXin Li
178*67e74705SXin Li  b = var_cmp >= arg_gen;
179*67e74705SXin Li#ifdef CONSTANT
180*67e74705SXin Li// expected-error@-2{{comparison between  ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}}
181*67e74705SXin Li#endif
182*67e74705SXin Li
183*67e74705SXin Li  AS int *var_sub;
184*67e74705SXin Li  b = var_sub - arg_glob;
185*67e74705SXin Li#ifdef CONSTANT
186*67e74705SXin Li// expected-error@-2{{arithmetic operation with operands of type  ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}}
187*67e74705SXin Li#endif
188*67e74705SXin Li
189*67e74705SXin Li  b = var_sub - arg_loc;
190*67e74705SXin Li#ifndef GENERIC
191*67e74705SXin Li// expected-error-re@-2{{arithmetic operation with operands of type  ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}}
192*67e74705SXin Li#endif
193*67e74705SXin Li
194*67e74705SXin Li  b = var_sub - arg_const;
195*67e74705SXin Li#ifndef CONSTANT
196*67e74705SXin Li// expected-error-re@-2{{arithmetic operation with operands of type  ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}}
197*67e74705SXin Li#endif
198*67e74705SXin Li
199*67e74705SXin Li  b = var_sub - arg_priv;
200*67e74705SXin Li#ifndef GENERIC
201*67e74705SXin Li// expected-error-re@-2{{arithmetic operation with operands of type  ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}}
202*67e74705SXin Li#endif
203*67e74705SXin Li
204*67e74705SXin Li  b = var_sub - arg_gen;
205*67e74705SXin Li#ifdef CONSTANT
206*67e74705SXin Li// expected-error@-2{{arithmetic operation with operands of type  ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}}
207*67e74705SXin Li#endif
208*67e74705SXin Li
209*67e74705SXin Li  f_glob(var_sub);
210*67e74705SXin Li#ifndef GLOBAL
211*67e74705SXin Li// expected-error-re@-2{{passing '__{{constant|generic}} int *' to parameter of type '__global int *' changes address space of pointer}}
212*67e74705SXin Li#endif
213*67e74705SXin Li
214*67e74705SXin Li  f_loc(var_sub); // expected-error-re{{passing '__{{global|constant|generic}} int *' to parameter of type '__local int *' changes address space of pointer}}
215*67e74705SXin Li
216*67e74705SXin Li  f_const(var_sub);
217*67e74705SXin Li#ifndef CONSTANT
218*67e74705SXin Li// expected-error-re@-2{{passing '__{{global|generic}} int *' to parameter of type '__constant int *' changes address space of pointer}}
219*67e74705SXin Li#endif
220*67e74705SXin Li
221*67e74705SXin Li  f_priv(var_sub); // expected-error-re{{passing '__{{global|constant|generic}} int *' to parameter of type 'int *' changes address space of pointer}}
222*67e74705SXin Li
223*67e74705SXin Li  f_gen(var_sub);
224*67e74705SXin Li#ifdef CONSTANT
225*67e74705SXin Li// expected-error@-2{{passing '__constant int *' to parameter of type '__generic int *' changes address space of pointer}}
226*67e74705SXin Li#endif
227*67e74705SXin Li}
228*67e74705SXin Li
229*67e74705SXin Livoid test_ternary() {
230*67e74705SXin Li  AS int *var_cond;
231*67e74705SXin Li  generic int *var_gen;
232*67e74705SXin Li  global int *var_glob;
233*67e74705SXin Li  var_gen = 0 ? var_cond : var_glob;
234*67e74705SXin Li#ifdef CONSTANT
235*67e74705SXin Li// expected-error@-2{{conditional operator with the second and third operands of type  ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}}
236*67e74705SXin Li#endif
237*67e74705SXin Li
238*67e74705SXin Li  local int *var_loc;
239*67e74705SXin Li  var_gen = 0 ? var_cond : var_loc;
240*67e74705SXin Li#ifndef GENERIC
241*67e74705SXin Li// expected-error-re@-2{{conditional operator with the second and third operands of type  ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}}
242*67e74705SXin Li#endif
243*67e74705SXin Li
244*67e74705SXin Li  constant int *var_const;
245*67e74705SXin Li  var_cond = 0 ? var_cond : var_const;
246*67e74705SXin Li#ifndef CONSTANT
247*67e74705SXin Li// expected-error-re@-2{{conditional operator with the second and third operands of type  ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}}
248*67e74705SXin Li#endif
249*67e74705SXin Li
250*67e74705SXin Li  private int *var_priv;
251*67e74705SXin Li  var_gen = 0 ? var_cond : var_priv;
252*67e74705SXin Li#ifndef GENERIC
253*67e74705SXin Li// expected-error-re@-2{{conditional operator with the second and third operands of type  ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}}
254*67e74705SXin Li#endif
255*67e74705SXin Li
256*67e74705SXin Li  var_gen = 0 ? var_cond : var_gen;
257*67e74705SXin Li#ifdef CONSTANT
258*67e74705SXin Li// expected-error@-2{{conditional operator with the second and third operands of type  ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}}
259*67e74705SXin Li#endif
260*67e74705SXin Li
261*67e74705SXin Li  void *var_void_gen;
262*67e74705SXin Li  global char *var_glob_ch;
263*67e74705SXin Li  var_void_gen = 0 ? var_cond : var_glob_ch;
264*67e74705SXin Li#ifdef CONSTANT
265*67e74705SXin Li// expected-error@-2{{conditional operator with the second and third operands of type  ('__constant int *' and '__global char *') which are pointers to non-overlapping address spaces}}
266*67e74705SXin Li#endif
267*67e74705SXin Li
268*67e74705SXin Li  local char *var_loc_ch;
269*67e74705SXin Li  var_void_gen = 0 ? var_cond : var_loc_ch;
270*67e74705SXin Li#ifndef GENERIC
271*67e74705SXin Li// expected-error-re@-2{{conditional operator with the second and third operands of type  ('__{{global|constant}} int *' and '__local char *') which are pointers to non-overlapping address spaces}}
272*67e74705SXin Li#endif
273*67e74705SXin Li
274*67e74705SXin Li  constant void *var_void_const;
275*67e74705SXin Li  constant char *var_const_ch;
276*67e74705SXin Li  var_void_const = 0 ? var_cond : var_const_ch;
277*67e74705SXin Li#ifndef CONSTANT
278*67e74705SXin Li// expected-error-re@-2{{conditional operator with the second and third operands of type  ('__{{global|generic}} int *' and '__constant char *') which are pointers to non-overlapping address spaces}}
279*67e74705SXin Li#endif
280*67e74705SXin Li
281*67e74705SXin Li  private char *var_priv_ch;
282*67e74705SXin Li  var_void_gen = 0 ? var_cond : var_priv_ch;
283*67e74705SXin Li#ifndef GENERIC
284*67e74705SXin Li// expected-error-re@-2{{conditional operator with the second and third operands of type  ('__{{global|constant}} int *' and 'char *') which are pointers to non-overlapping address spaces}}
285*67e74705SXin Li#endif
286*67e74705SXin Li
287*67e74705SXin Li  generic char *var_gen_ch;
288*67e74705SXin Li  var_void_gen = 0 ? var_cond : var_gen_ch;
289*67e74705SXin Li#ifdef CONSTANT
290*67e74705SXin Li// expected-error@-2{{conditional operator with the second and third operands of type  ('__constant int *' and '__generic char *') which are pointers to non-overlapping address spaces}}
291*67e74705SXin Li#endif
292*67e74705SXin Li}
293*67e74705SXin Li
294