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
++
5 // RUN
: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std
=clc
++
6 // RUN
: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std
=clc
++
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.
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).
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.
24 #define AS_COMP __local
25 #define AS_INCOMP __constant
30 #define AS_COMP __global
31 #define AS_INCOMP __local
36 #define AS_COMP __constant
37 #define AS_INCOMP __global
40 void f_glob
(__global int
*arg_glob
) {}
42 #if
!__OPENCL_CPP_VERSION__
43 // expected-note
@-
3{{passing argument to parameter
'arg_glob
' here
}}
45 // 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
}}
49 void f_loc
(__local int
*arg_loc
) {}
50 #if
!__OPENCL_CPP_VERSION__
51 // expected-note
@-
2{{passing argument to parameter
'arg_loc
' here
}}
53 // 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
}}
56 void f_const
(__constant int
*arg_const
) {}
58 #if
!__OPENCL_CPP_VERSION__
59 // expected-note
@-
3{{passing argument to parameter
'arg_const
' here
}}
61 // 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
}}
65 void f_priv
(__private int
*arg_priv
) {}
66 #if
!__OPENCL_CPP_VERSION__
67 // expected-note
@-
2{{passing argument to parameter
'arg_priv
' here
}}
69 // 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
}}
72 void f_gen
(__generic int
*arg_gen
) {}
74 #if
!__OPENCL_CPP_VERSION__
75 // expected-note
@-
3{{passing argument to parameter
'arg_gen
' here
}}
77 // expected-note
@-
5{{candidate function not viable
: cannot pass pointer to address space
'__constant
' as a pointer to address space
'__generic
' in
1st argument
}}
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
) {
85 AS int
*var_init1
= arg_glob
;
87 #if
!__OPENCL_CPP_VERSION__
88 // expected-error
@-
3{{initializing
'__constant int
*__private
' with an expression of type
'__global int
*__private
' changes address space of pointer
}}
90 // expected-error
@-
5{{cannot initialize a variable of type
'__constant int
*__private
' with an lvalue of type
'__global int
*__private
'}}
94 AS int
*var_init2
= arg_loc
;
96 #if
!__OPENCL_CPP_VERSION__
97 // expected-error-re
@-
3{{initializing
'__
{{global|constant
}} int
*__private
' with an expression of type
'__local int
*__private
' changes address space of pointer
}}
99 // expected-error-re
@-
5{{cannot initialize a variable of type
'__
{{global|constant
}} int
*__private
' with an lvalue of type
'__local int
*__private
'}}
103 AS int
*var_init3
= arg_const
;
105 #if
!__OPENCL_CPP_VERSION__
106 // expected-error-re
@-
3{{initializing
'__
{{global|generic
}} int
*__private
' with an expression of type
'__constant int
*__private
' changes address space of pointer
}}
108 // expected-error-re
@-
5{{cannot initialize a variable of type
'__
{{global|generic
}} int
*__private
' with an lvalue of type
'__constant int
*__private
'}}
112 AS int
*var_init4
= arg_priv
;
114 #if
!__OPENCL_CPP_VERSION__
115 // expected-error-re
@-
3{{initializing
'__
{{global|constant
}} int
*__private
' with an expression of type
'__private int
*__private
' changes address space of pointer
}}
117 // expected-error-re
@-
5{{cannot initialize a variable of type
'__
{{global|constant
}} int
*__private
' with an lvalue of type
'__private int
*__private
'}}
121 AS int
*var_init5
= arg_gen
;
123 #if
!__OPENCL_CPP_VERSION__
124 // expected-error-re
@-
3{{initializing
'__
{{global|constant
}} int
*__private
' with an expression of type
'__generic int
*__private
' changes address space of pointer
}}
126 // expected-error-re
@-
5{{cannot initialize a variable of type
'__
{{global|constant
}} int
*__private
' with an lvalue of type
'__generic int
*__private
'}}
130 AS int
*var_cast1
= (AS int
*)arg_glob
;
132 #if
!__OPENCL_CPP_VERSION__
133 // expected-error
@-
3{{casting
'__global int
*' to type
'__constant int
*' changes address space of pointer
}}
135 // expected-error
@-
5{{C-style cast from
'__global int
*' to
'__constant int
*' converts between mismatching address spaces
}}
139 AS int
*var_cast2
= (AS int
*)arg_loc
;
141 #if
!__OPENCL_CPP_VERSION__
142 // expected-error-re
@-
3{{casting
'__local int
*' to type
'__
{{global|constant
}} int
*' changes address space of pointer
}}
144 // expected-error-re
@-
5{{C-style cast from
'__local int
*' to
'__
{{global|constant
}} int
*' converts between mismatching address spaces
}}
148 AS int
*var_cast3
= (AS int
*)arg_const
;
150 #if
!__OPENCL_CPP_VERSION__
151 // expected-error-re
@-
3{{casting
'__constant int
*' to type
'__
{{global|generic
}} int
*' changes address space of pointer
}}
153 // expected-error-re
@-
5{{C-style cast from
'__constant int
*' to
'__
{{global|generic
}} int
*' converts between mismatching address spaces
}}
157 AS int
*var_cast4
= (AS int
*)arg_priv
;
159 #if
!__OPENCL_CPP_VERSION__
160 // expected-error-re
@-
3{{casting
'__private int
*' to type
'__
{{global|constant
}} int
*' changes address space of pointer
}}
162 // expected-error-re
@-
5{{C-style cast from
'__private int
*' to
'__
{{global|constant
}} int
*' converts between mismatching address spaces
}}
166 AS int
*var_cast5
= (AS int
*)arg_gen
;
168 #if
!__OPENCL_CPP_VERSION__
169 // expected-error
@-
3{{casting
'__generic int
*' to type
'__constant int
*' changes address space of pointer
}}
171 // expected-error
@-
5{{C-style cast from
'__generic int
*' to
'__constant int
*' converts between mismatching address spaces
}}
178 #if
!__OPENCL_CPP_VERSION__
179 // expected-error
@-
3{{assigning
'__global int
*__private
' to
'__constant int
*__private
' changes address space of pointer
}}
181 // expected-error
@-
5{{assigning to
'__constant int
*' from incompatible type
'__global int
*__private
'}}
187 #if
!__OPENCL_CPP_VERSION__
188 // expected-error-re
@-
3{{assigning
'__local int
*__private
' to
'__
{{global|constant
}} int
*__private
' changes address space of pointer
}}
190 // expected-error-re
@-
5{{assigning to
'__
{{global|constant
}} int
*' from incompatible type
'__local int
*__private
'}}
194 var_impl
= arg_const
;
196 #if
!__OPENCL_CPP_VERSION__
197 // expected-error-re
@-
3{{assigning
'__constant int
*__private
' to
'__
{{global|generic
}} int
*__private
' changes address space of pointer
}}
199 // expected-error-re
@-
5{{assigning to
'__
{{global|generic
}} int
*' from incompatible type
'__constant int
*__private
'}}
205 #if
!__OPENCL_CPP_VERSION__
206 // expected-error-re
@-
3{{assigning
'__private int
*__private
' to
'__
{{global|constant
}} int
*__private
' changes address space of pointer
}}
208 // expected-error-re
@-
5{{assigning to
'__
{{global|constant
}} int
*' from incompatible type
'__private int
*__private
'}}
214 #if
!__OPENCL_CPP_VERSION__
215 // expected-error-re
@-
3{{assigning
'__generic int
*__private
' to
'__
{{global|constant
}} int
*__private
' changes address space of pointer
}}
217 // expected-error-re
@-
5{{assigning to
'__
{{global|constant
}} int
*' from incompatible type
'__generic int
*__private
'}}
221 var_cast1
= (AS int
*)arg_glob
;
223 #if
!__OPENCL_CPP_VERSION__
224 // expected-error
@-
3{{casting
'__global int
*' to type
'__constant int
*' changes address space of pointer
}}
226 // expected-error
@-
5{{C-style cast from
'__global int
*' to
'__constant int
*' converts between mismatching address spaces
}}
230 var_cast2
= (AS int
*)arg_loc
;
232 #if
!__OPENCL_CPP_VERSION__
233 // expected-error-re
@-
3{{casting
'__local int
*' to type
'__
{{global|constant
}} int
*' changes address space of pointer
}}
235 // expected-error-re
@-
5{{C-style cast from
'__local int
*' to
'__
{{global|constant
}} int
*' converts between mismatching address spaces
}}
239 var_cast3
= (AS int
*)arg_const
;
241 #if
!__OPENCL_CPP_VERSION__
242 // expected-error-re
@-
3{{casting
'__constant int
*' to type
'__
{{global|generic
}} int
*' changes address space of pointer
}}
244 // expected-error-re
@-
5{{C-style cast from
'__constant int
*' to
'__
{{global|generic
}} int
*' converts between mismatching address spaces
}}
248 var_cast4
= (AS int
*)arg_priv
;
250 #if
!__OPENCL_CPP_VERSION__
251 // expected-error-re
@-
3{{casting
'__private int
*' to type
'__
{{global|constant
}} int
*' changes address space of pointer
}}
253 // expected-error-re
@-
5{{C-style cast from
'__private int
*' to
'__
{{global|constant
}} int
*' converts between mismatching address spaces
}}
257 var_cast5
= (AS int
*)arg_gen
;
259 #if
!__OPENCL_CPP_VERSION__
260 // expected-error
@-
3{{casting
'__generic int
*' to type
'__constant int
*' changes address space of pointer
}}
262 // expected-error
@-
5{{C-style cast from
'__generic int
*' to
'__constant int
*' converts between mismatching address spaces
}}
267 int b
= var_cmp
!= arg_glob
;
269 #if
!__OPENCL_CPP_VERSION__
270 // expected-error
@-
3{{comparison between
('__constant int
*' and
'__global int
*') which are pointers to non-overlapping address spaces
}}
272 // expected-error
@-
5{{comparison of distinct pointer types
('__constant int
*' and
'__global int
*')}}
276 b
= var_cmp
!= arg_loc
;
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
}}
281 // expected-error-re
@-
5{{comparison of distinct pointer types
('__
{{global|constant
}} int
*' and
'__local int
*')}}
285 b
= var_cmp
== arg_const
;
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
}}
290 // expected-error-re
@-
5{{comparison of distinct pointer types
('__
{{global|generic
}} int
*' and
'__constant int
*')}}
294 b
= var_cmp
<= arg_priv
;
296 #if
!__OPENCL_CPP_VERSION__
297 // expected-error-re
@-
3{{comparison between
('__
{{global|constant
}} int
*' and
'__private int
*') which are pointers to non-overlapping address spaces
}}
299 // expected-error-re
@-
5{{comparison of distinct pointer types
('__
{{global|constant
}} int
*' and
'__private int
*')}}
303 b
= var_cmp
>= arg_gen
;
305 #if
!__OPENCL_CPP_VERSION__
306 // expected-error
@-
3{{comparison between
('__constant int
*' and
'__generic int
*') which are pointers to non-overlapping address spaces
}}
308 // expected-error
@-
5{{comparison of distinct pointer types
('__constant int
*' and
'__generic int
*')}}
313 b
= var_sub - arg_glob
;
315 // expected-error
@-
2{{arithmetic operation with operands of type
('__constant int
*' and
'__global int
*') which are pointers to non-overlapping address spaces
}}
318 b
= var_sub - arg_loc
;
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
}}
323 b
= var_sub - arg_const
;
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
}}
328 b
= var_sub - arg_priv
;
330 // expected-error-re
@-
2{{arithmetic operation with operands of type
('__
{{global|constant
}} int
*' and
'__private int
*') which are pointers to non-overlapping address spaces
}}
333 b
= var_sub - arg_gen
;
335 // expected-error
@-
2{{arithmetic operation with operands of type
('__constant int
*' and
'__generic int
*') which are pointers to non-overlapping address spaces
}}
340 #if
!__OPENCL_CPP_VERSION__
341 // expected-error-re
@-
3{{passing
'__
{{constant|generic
}} int
*__private
' to parameter of type
'__global int
*' changes address space of pointer
}}
343 // expected-error
@-
5{{no matching function for call to
'f_glob
'}}
348 #if
!__OPENCL_CPP_VERSION__
349 // expected-error-re
@-
2{{passing
'__
{{global|constant|generic
}} int
*__private
' to parameter of type
'__local int
*' changes address space of pointer
}}
351 // expected-error
@-
4{{no matching function for call to
'f_loc
'}}
356 #if
!__OPENCL_CPP_VERSION__
357 // expected-error-re
@-
3{{passing
'__
{{global|generic
}} int
*__private
' to parameter of type
'__constant int
*' changes address space of pointer
}}
359 // expected-error
@-
5{{no matching function for call to
'f_const
'}}
364 #if
!__OPENCL_CPP_VERSION__
365 // expected-error-re
@-
2{{passing
'__
{{global|constant|generic
}} int
*__private
' to parameter of type
'__private int
*' changes address space of pointer
}}
367 // expected-error
@-
4{{no matching function for call to
'f_priv
'}}
372 #if
!__OPENCL_CPP_VERSION__
373 // expected-error
@-
3{{passing
'__constant int
*__private
' to parameter of type
'__generic int
*' changes address space of pointer
}}
375 // expected-error
@-
5{{no matching function for call to
'f_gen
'}}
380 void test_ternary
() {
382 __generic int
*var_gen
;
383 __global int
*var_glob
;
384 var_gen
= 0 ? var_cond
: var_glob
;
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
}}
389 // expected-error
@-
5{{incompatible operand types
('__constant int
*' and
'__global int
*')}}
393 __local int
*var_loc
;
394 var_gen
= 0 ? var_cond
: var_loc
;
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
}}
399 // expected-error-re
@-
5{{incompatible operand types
('__
{{global|constant
}} int
*' and
'__local int
*')}}
403 __constant int
*var_const
;
404 var_cond
= 0 ? var_cond
: var_const
;
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
}}
409 // expected-error-re
@-
5{{incompatible operand types
('__
{{global|generic
}} int
*' and
'__constant int
*')}}
413 __private int
*var_priv
;
414 var_gen
= 0 ? var_cond
: var_priv
;
416 #if
!__OPENCL_CPP_VERSION__
417 // 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
}}
419 // expected-error-re
@-
5{{incompatible operand types
('__
{{global|constant
}} int
*' and
'__private int
*')}}
423 var_gen
= 0 ? var_cond
: var_gen
;
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
}}
428 // expected-error
@-
5{{incompatible operand types
('__constant int
*' and
'__generic int
*')}}
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
*')}}
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
}}
441 // expected-warning-re
@-
7{{pointer type mismatch
('__
{{global|generic
}} int
*' and
'__global char
*')}}
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
*')}}
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
}}
453 // expected-warning
@-
7{{pointer type mismatch
('__generic int
*' and
'__local char
*')}}
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
*')}}
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
}}
466 // expected-warning
@-
7{{pointer type mismatch
('__constant int
*' and
'__constant char
*')}}
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
'__private char
*')}}
476 // 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
}}
478 // expected-warning
@-
7{{pointer type mismatch
('__generic int
*' and
'__private char
*')}}
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
*')}}
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
}}
490 // expected-warning-re
@-
7{{pointer type mismatch
('__
{{global|generic
}} int
*' and
'__generic char
*')}}
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
;
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
= var_asc_as_int
;
505 var_as_as_int
= 0 ? var_as_as_int
: var_asc_as_int
;
507 // Case
2: Corresponded inner pointees has non-overlapping address spaces.
508 var_as_as_int
= 0 ? var_as_as_int
: var_asc_asn_int
;
509 #if
!__OPENCL_CPP_VERSION__
510 // expected-warning-re
@-
2{{pointer type mismatch
('__
{{(generic|global|constant
)}} int
*__
{{(generic|global|constant
)}} *' and
'__
{{(local|global|constant
)}} int
*__
{{(constant|local|global
)}} *')}}
512 // expected-error-re
@-
4{{incompatible operand types
('__
{{(generic|global|constant
)}} int
*__
{{(generic|global|constant
)}} *' and
'__
{{(local|global|constant
)}} int
*__
{{(constant|local|global
)}} *')}}
515 // Case
3: Corresponded inner pointees has overlapping but not equivalent address spaces.
516 // FIXME
: Should this really be allowed in C
++ mode?
517 var_as_as_int
= var_asc_asc_int
;
518 #if
!__OPENCL_CPP_VERSION__
520 // expected-error
@-
3 {{assigning
'__local int
*__local
*__private
' to
'__generic int
*__generic
*__private
' changes address space of nested pointer
}}
523 var_as_as_int
= 0 ? var_as_as_int
: var_asc_asc_int
;
524 #if
!__OPENCL_CPP_VERSION__
526 // expected-warning
@-
3{{pointer type mismatch
('__generic int
*__generic
*' and
'__local int
*__local
*')}}