| 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; |
| 11 |
constant int G2 = 0; |
| 12 |
|
| 13 |
int G3 = 0; |
| 14 |
#ifndef __opencl_c_program_scope_global_variables |
| 15 |
// expected-error@-2 {{program scope variable must reside in constant address space}} |
| 16 |
#endif |
| 17 |
|
| 18 |
global int G4 = 0; |
| 19 |
#ifndef __opencl_c_program_scope_global_variables |
| 20 |
// expected-error@-2 {{program scope variable must reside in constant address space}} |
| 21 |
#endif |
| 22 |
|
| 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}} |
| 26 |
#endif |
| 27 |
|
| 28 |
static constant float g_constant_static_var = 0; |
| 29 |
|
| 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}} |
| 33 |
#endif |
| 34 |
|
| 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}} |
| 38 |
#else |
| 39 |
// expected-error@-4 {{program scope variable must reside in global or constant address space}} |
| 40 |
#endif |
| 41 |
|
| 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}} |
| 45 |
#else |
| 46 |
// expected-error@-4 {{program scope variable must reside in global or constant address space}} |
| 47 |
#endif |
| 48 |
|
| 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}} |
| 59 |
#endif |
| 60 |
#endif |
| 61 |
#if !defined(__opencl_c_program_scope_global_variables) |
| 62 |
// expected-error@-13 {{program scope variable must reside in constant address space}} |
| 63 |
#endif |
| 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}} |
| 66 |
#endif |
| 67 |
#endif |
| 68 |
|
| 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}} |
| 72 |
#endif |
| 73 |
|
| 74 |
extern constant float g_constant_extern_var; |
| 75 |
|
| 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}} |
| 79 |
#endif |
| 80 |
|
| 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}} |
| 84 |
#else |
| 85 |
// expected-error@-4 {{extern variable must reside in global or constant address space}} |
| 86 |
#endif |
| 87 |
|
| 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}} |
| 91 |
#else |
| 92 |
// expected-error@-4 {{extern variable must reside in global or constant address space}} |
| 93 |
#endif |
| 94 |
|
| 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}} |
| 105 |
#endif |
| 106 |
#endif |
| 107 |
#if !defined(__opencl_c_program_scope_global_variables) |
| 108 |
// expected-error@-13 {{extern variable must reside in constant address space}} |
| 109 |
#endif |
| 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}} |
| 112 |
#endif |
| 113 |
#endif |
| 114 |
|
| 115 |
void kernel foo(int x) { |
| 116 |
// static is not allowed at local scope before CL2.0 |
| 117 |
static int S1 = 5; |
| 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}} |
| 122 |
#endif |
| 123 |
|
| 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}} |
| 127 |
#endif |
| 128 |
|
| 129 |
constant int L1 = 0; |
| 130 |
local int L2; |
| 131 |
|
| 132 |
if (true) { |
| 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}} |
| 135 |
} |
| 136 |
|
| 137 |
auto int L3 = 7; |
| 138 |
#if (__OPENCL_CPP_VERSION__ == 202100) |
| 139 |
// expected-error@-2{{C++ for OpenCL version 2021 does not support the 'auto' storage class specifier}} |
| 140 |
#else |
| 141 |
// expected-error-re@-4{{OpenCL C version {{1.2|3.0}} does not support the 'auto' storage class specifier}} |
| 142 |
#endif |
| 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}} |
| 145 |
|
| 146 |
constant int L6 = x; // expected-error {{initializer element is not a compile-time constant}} |
| 147 |
global int *constant L7 = &G4; |
| 148 |
|
| 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}} |
| 152 |
} |
| 153 |
|
| 154 |
static void kernel bar(void) { // expected-error{{kernel functions cannot be declared static}} |
| 155 |
} |
| 156 |
|
| 157 |
void f(void) { |
| 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}} |
| 162 |
|
| 163 |
{ |
| 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}} |
| 168 |
} |
| 169 |
|
| 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}} |
| 175 |
#endif |
| 176 |
|
| 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}} |
| 180 |
#endif |
| 181 |
|
| 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}} |
| 187 |
#endif |
| 188 |
|
| 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}} |
| 196 |
#endif |
| 197 |
|
| 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}} |
| 205 |
#endif |
| 206 |
|
| 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}} |
| 217 |
#endif |
| 218 |
#endif |
| 219 |
#if !defined(__opencl_c_program_scope_global_variables) |
| 220 |
// expected-error@-13 {{static local variable must reside in constant address space}} |
| 221 |
#endif |
| 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}} |
| 224 |
#endif |
| 225 |
#endif |
| 226 |
|
| 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}} |
| 232 |
#endif |
| 233 |
|
| 234 |
extern constant float l_constant_extern_var; |
| 235 |
|
| 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}} |
| 241 |
#endif |
| 242 |
|
| 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}} |
| 250 |
#endif |
| 251 |
|
| 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}} |
| 259 |
#endif |
| 260 |
|
| 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}} |
| 271 |
#endif |
| 272 |
#endif |
| 273 |
#if !defined(__opencl_c_program_scope_global_variables) |
| 274 |
// expected-error@-13 {{extern variable must reside in constant address space}} |
| 275 |
#endif |
| 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}} |
| 278 |
#endif |
| 279 |
#endif |
| 280 |
} |