1 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=CL1.2
2 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=CL3.0 -cl-ext
=-all
3 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=CL3.0 -cl-ext
=-all
,+__opencl_c_program_scope_global_variables
4 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=CL3.0 -cl-ext
=-all
,+__opencl_c_generic_address_space
5 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=CL3.0 -cl-ext
=-all
,+__opencl_c_program_scope_global_variables
,+__opencl_c_generic_address_space
6 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=clc
++2021 -cl-ext
=-all
7 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=clc
++2021 -cl-ext
=-all
,+__opencl_c_program_scope_global_variables
8 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=clc
++2021 -cl-ext
=-all
,+__opencl_c_generic_address_space
9 // RUN
: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std
=clc
++2021 -cl-ext
=-all
,+__opencl_c_program_scope_global_variables
,+__opencl_c_generic_address_space
10 static constant int G1
= 0;
14 #ifndef __opencl_c_program_scope_global_variables
15 // expected-error
@-
2 {{program scope variable must reside in constant address space
}}
19 #ifndef __opencl_c_program_scope_global_variables
20 // expected-error
@-
2 {{program scope variable must reside in constant address space
}}
23 static float g_implicit_static_var
= 0;
24 #ifndef __opencl_c_program_scope_global_variables
25 // expected-error
@-
2 {{program scope variable must reside in constant address space
}}
28 static constant float g_constant_static_var
= 0;
30 static global float g_global_static_var
= 0;
31 #ifndef __opencl_c_program_scope_global_variables
32 // expected-error
@-
2 {{program scope variable must reside in constant address space
}}
35 static local float g_local_static_var
= 0;
36 #ifndef __opencl_c_program_scope_global_variables
37 // expected-error
@-
2 {{program scope variable must reside in constant address space
}}
39 // expected-error
@-
4 {{program scope variable must reside in global or constant address space
}}
42 static private float g_private_static_var
= 0;
43 #ifndef __opencl_c_program_scope_global_variables
44 // expected-error
@-
2 {{program scope variable must reside in constant address space
}}
46 // expected-error
@-
4 {{program scope variable must reside in global or constant address space
}}
49 static generic float g_generic_static_var
= 0;
50 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
51 // expected-error
@-
2 {{OpenCL C version
1.2 does not support the
'generic
' type qualifier
}}
52 // expected-error
@-
3 {{program scope variable must reside in constant address space
}}
53 #elif
(__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__
== 300)
54 #if
!defined
(__opencl_c_generic_address_space)
55 #if
(__OPENCL_C_VERSION__ == 300)
56 // expected-error
@-
7 {{OpenCL C version
3.0 does not support the
'generic
' type qualifier
}}
57 #elif
(__OPENCL_CPP_VERSION__ == 202100)
58 // expected-error
@-
9 {{C
++ for OpenCL version
2021 does not support the
'generic
' type qualifier
}}
61 #if
!defined
(__opencl_c_program_scope_global_variables)
62 // expected-error
@-
13 {{program scope variable must reside in constant address space
}}
64 #if defined
(__opencl_c_generic_address_space) && defined
(__opencl_c_program_scope_global_variables)
65 // expected-error
@-
16 {{program scope variable must reside in global or constant address space
}}
69 extern float g_implicit_extern_var
;
70 #ifndef __opencl_c_program_scope_global_variables
71 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
74 extern constant float g_constant_extern_var
;
76 extern global float g_global_extern_var
;
77 #ifndef __opencl_c_program_scope_global_variables
78 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
81 extern local float g_local_extern_var
;
82 #ifndef __opencl_c_program_scope_global_variables
83 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
85 // expected-error
@-
4 {{extern variable must reside in global or constant address space
}}
88 extern private float g_private_extern_var
;
89 #ifndef __opencl_c_program_scope_global_variables
90 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
92 // expected-error
@-
4 {{extern variable must reside in global or constant address space
}}
95 extern generic float g_generic_extern_var
;
96 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
97 // expected-error
@-
2 {{OpenCL C version
1.2 does not support the
'generic
' type qualifier
}}
98 // expected-error
@-
3 {{extern variable must reside in constant address space
}}
99 #elif
(__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__
== 300)
100 #if
!defined
(__opencl_c_generic_address_space)
101 #if
(__OPENCL_C_VERSION__ == 300)
102 // expected-error
@-
7 {{OpenCL C version
3.0 does not support the
'generic
' type qualifier
}}
103 #elif
(__OPENCL_CPP_VERSION__ == 202100)
104 // expected-error
@-
9 {{C
++ for OpenCL version
2021 does not support the
'generic
' type qualifier
}}
107 #if
!defined
(__opencl_c_program_scope_global_variables)
108 // expected-error
@-
13 {{extern variable must reside in constant address space
}}
110 #if defined
(__opencl_c_generic_address_space) && defined
(__opencl_c_program_scope_global_variables)
111 // expected-error
@-
16 {{extern variable must reside in global or constant address space
}}
115 void kernel foo
(int x
) {
116 // static is not allowed at local scope before CL2.0
118 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
119 // expected-error
@-
2 {{variables in function scope cannot be declared static
}}
120 #elif
!defined
(__opencl_c_program_scope_global_variables)
121 // expected-error
@-
4 {{static local variable must reside in constant address space
}}
124 static constant int S2
= 5;
125 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
126 // expected-error
@-
2 {{variables in function scope cannot be declared static
}}
133 local int L1
; // expected-error {{variables in the local address space can only be declared in the outermost scope of a kernel function}}
134 constant int L1
= 42; // expected-error {{variables in the constant address space can only be declared in the outermost scope of a kernel function}}
138 #if
(__OPENCL_CPP_VERSION__ == 202100)
139 // expected-error
@-
2{{C
++ for OpenCL version
2021 does not support the
'auto
' storage class specifier
}}
141 // expected-error-re
@-
4{{OpenCL C version
{{1.2|
3.0}} does not support the
'auto
' storage class specifier
}}
143 global int L4
; // expected-error{{function scope variable cannot be declared in global address space}}
144 __attribute__
((address_space(100))) int L5
; // expected-error{{automatic variable qualified with an invalid address space}}
146 constant int L6
= x
; // expected-error {{initializer element is not a compile-time constant}}
147 global int
*constant L7
= &G4
;
149 private int
*constant L8
= &x
; // expected-error {{initializer element is not a compile-time constant}}
150 constant int
*constant L9
= &L1
;
151 local int
*constant L10
= &L2
; // expected-error {{initializer element is not a compile-time constant}}
154 static void kernel bar
(void) { // expected-error
{{kernel functions cannot be declared static
}}
158 constant int L1
= 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
159 local int L2
; // expected-error{{non-kernel function variable cannot be declared in local address space}}
160 global int L3
; // expected-error{{function scope variable cannot be declared in global address space}}
161 __attribute__
((address_space(100))) int L4
; // expected-error{{automatic variable qualified with an invalid address space}}
164 constant int L1
= 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
165 local int L2
; // expected-error{{non-kernel function variable cannot be declared in local address space}}
166 global int L3
; // expected-error{{function scope variable cannot be declared in global address space}}
167 __attribute__
((address_space(100))) int L4
; // expected-error{{automatic variable qualified with an invalid address space}}
170 static float l_implicit_static_var
= 0;
171 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
172 // expected-error
@-
2 {{variables in function scope cannot be declared static
}}
173 #elif
!defined
(__opencl_c_program_scope_global_variables)
174 // expected-error
@-
4 {{static local variable must reside in constant address space
}}
177 static constant float l_constant_static_var
= 0;
178 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
179 // expected-error
@-
2 {{variables in function scope cannot be declared static
}}
182 static global float l_global_static_var
= 0;
183 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
184 // expected-error
@-
2 {{variables in function scope cannot be declared static
}}
185 #elif
!defined
(__opencl_c_program_scope_global_variables)
186 // expected-error
@-
4 {{static local variable must reside in constant address space
}}
189 static local float l_local_static_var
= 0;
190 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
191 // expected-error
@-
2 {{variables in function scope cannot be declared static
}}
192 #elif
!defined
(__opencl_c_program_scope_global_variables)
193 // expected-error
@-
4 {{static local variable must reside in constant address space
}}
194 #elif defined
(__opencl_c_program_scope_global_variables)
195 // expected-error
@-
6 {{static local variable must reside in global or constant address space
}}
198 static private float l_private_static_var
= 0;
199 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
200 // expected-error
@-
2 {{variables in function scope cannot be declared static
}}
201 #elif
!defined
(__opencl_c_program_scope_global_variables)
202 // expected-error
@-
4 {{static local variable must reside in constant address space
}}
203 #elif defined
(__opencl_c_program_scope_global_variables)
204 // expected-error
@-
6 {{static local variable must reside in global or constant address space
}}
207 static generic float l_generic_static_var
= 0;
208 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
209 // expected-error
@-
2 {{OpenCL C version
1.2 does not support the
'generic
' type qualifier
}}
210 // expected-error
@-
3 {{variables in function scope cannot be declared static
}}
211 #elif
(__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__
== 300)
212 #if
!defined
(__opencl_c_generic_address_space)
213 #if
(__OPENCL_C_VERSION__ == 300)
214 // expected-error
@-
7 {{OpenCL C version
3.0 does not support the
'generic
' type qualifier
}}
215 #elif
(__OPENCL_CPP_VERSION__ == 202100)
216 // expected-error
@-
9 {{C
++ for OpenCL version
2021 does not support the
'generic
' type qualifier
}}
219 #if
!defined
(__opencl_c_program_scope_global_variables)
220 // expected-error
@-
13 {{static local variable must reside in constant address space
}}
222 #if defined
(__opencl_c_generic_address_space) && defined
(__opencl_c_program_scope_global_variables)
223 // expected-error
@-
16 {{static local variable must reside in global or constant address space
}}
227 extern float l_implicit_extern_var
;
228 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
229 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
230 #elif
!defined
(__opencl_c_program_scope_global_variables)
231 // expected-error
@-
4 {{extern variable must reside in constant address space
}}
234 extern constant float l_constant_extern_var
;
236 extern global float l_global_extern_var
;
237 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
238 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
239 #elif
!defined
(__opencl_c_program_scope_global_variables)
240 // expected-error
@-
4 {{extern variable must reside in constant address space
}}
243 extern local float l_local_extern_var
;
244 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
245 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
246 #elif
!defined
(__opencl_c_program_scope_global_variables)
247 // expected-error
@-
4 {{extern variable must reside in constant address space
}}
248 #elif defined
(__opencl_c_program_scope_global_variables)
249 // expected-error
@-
6 {{extern variable must reside in global or constant address space
}}
252 extern private float l_private_extern_var
;
253 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
254 // expected-error
@-
2 {{extern variable must reside in constant address space
}}
255 #elif
!defined
(__opencl_c_program_scope_global_variables)
256 // expected-error
@-
4 {{extern variable must reside in constant address space
}}
257 #elif defined
(__opencl_c_program_scope_global_variables)
258 // expected-error
@-
6 {{extern variable must reside in global or constant address space
}}
261 extern generic float l_generic_extern_var
;
262 #if
(defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__
< 300)
263 // expected-error
@-
2 {{OpenCL C version
1.2 does not support the
'generic
' type qualifier
}}
264 // expected-error
@-
3 {{extern variable must reside in constant address space
}}
265 #elif
(__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__
== 300)
266 #if
!defined
(__opencl_c_generic_address_space)
267 #if
(__OPENCL_C_VERSION__ == 300)
268 // expected-error
@-
7 {{OpenCL C version
3.0 does not support the
'generic
' type qualifier
}}
269 #elif
(__OPENCL_CPP_VERSION__ == 202100 && !defined
(__opencl_c_generic_address_space))
270 // expected-error
@-
9 {{C
++ for OpenCL version
2021 does not support the
'generic
' type qualifier
}}
273 #if
!defined
(__opencl_c_program_scope_global_variables)
274 // expected-error
@-
13 {{extern variable must reside in constant address space
}}
276 #if defined
(__opencl_c_generic_address_space) && defined
(__opencl_c_program_scope_global_variables)
277 // expected-error
@-
16 {{extern variable must reside in global or constant address space
}}