281 lines · plain
1// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.22// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all3// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_program_scope_global_variables4// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_generic_address_space5// 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_space6// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all7// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_program_scope_global_variables8// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_generic_address_space9// 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_space10static constant int G1 = 0;11constant int G2 = 0;12 13int G3 = 0;14#ifndef __opencl_c_program_scope_global_variables15// expected-error@-2 {{program scope variable must reside in constant address space}}16#endif17 18global int G4 = 0;19#ifndef __opencl_c_program_scope_global_variables20// expected-error@-2 {{program scope variable must reside in constant address space}}21#endif22 23static float g_implicit_static_var = 0;24#ifndef __opencl_c_program_scope_global_variables25// expected-error@-2 {{program scope variable must reside in constant address space}}26#endif27 28static constant float g_constant_static_var = 0;29 30static global float g_global_static_var = 0;31#ifndef __opencl_c_program_scope_global_variables32// expected-error@-2 {{program scope variable must reside in constant address space}}33#endif34 35static local float g_local_static_var = 0;36#ifndef __opencl_c_program_scope_global_variables37// expected-error@-2 {{program scope variable must reside in constant address space}}38#else39// expected-error@-4 {{program scope variable must reside in global or constant address space}}40#endif41 42static private float g_private_static_var = 0;43#ifndef __opencl_c_program_scope_global_variables44// expected-error@-2 {{program scope variable must reside in constant address space}}45#else46// expected-error@-4 {{program scope variable must reside in global or constant address space}}47#endif48 49static 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#endif60#endif61#if !defined(__opencl_c_program_scope_global_variables)62// expected-error@-13 {{program scope variable must reside in constant address space}}63#endif64#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#endif67#endif68 69extern float g_implicit_extern_var;70#ifndef __opencl_c_program_scope_global_variables71// expected-error@-2 {{extern variable must reside in constant address space}}72#endif73 74extern constant float g_constant_extern_var;75 76extern global float g_global_extern_var;77#ifndef __opencl_c_program_scope_global_variables78// expected-error@-2 {{extern variable must reside in constant address space}}79#endif80 81extern local float g_local_extern_var;82#ifndef __opencl_c_program_scope_global_variables83// expected-error@-2 {{extern variable must reside in constant address space}}84#else85// expected-error@-4 {{extern variable must reside in global or constant address space}}86#endif87 88extern private float g_private_extern_var;89#ifndef __opencl_c_program_scope_global_variables90// expected-error@-2 {{extern variable must reside in constant address space}}91#else92// expected-error@-4 {{extern variable must reside in global or constant address space}}93#endif94 95extern 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#endif106#endif107#if !defined(__opencl_c_program_scope_global_variables)108// expected-error@-13 {{extern variable must reside in constant address space}}109#endif110#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#endif113#endif114 115void kernel foo(int x) {116 // static is not allowed at local scope before CL2.0117 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#endif123 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#endif128 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#else141// expected-error-re@-4{{OpenCL C version {{1.2|3.0}} does not support the 'auto' storage class specifier}}142#endif143 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 154static void kernel bar(void) { // expected-error{{kernel functions cannot be declared static}}155}156 157void 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#endif176 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#endif181 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#endif188 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#endif197 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#endif206 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#endif218#endif219#if !defined(__opencl_c_program_scope_global_variables)220// expected-error@-13 {{static local variable must reside in constant address space}}221#endif222#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#endif225#endif226 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#endif233 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#endif242 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#endif251 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#endif260 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#endif272#endif273#if !defined(__opencl_c_program_scope_global_variables)274// expected-error@-13 {{extern variable must reside in constant address space}}275#endif276#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#endif279#endif280}281