[clang] 054e331 - [OpenCL] Supports optional program scope global variables in C++ for OpenCL 2021
Justas Janickas via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 16 04:48:24 PDT 2021
Author: Justas Janickas
Date: 2021-09-16T12:48:01+01:00
New Revision: 054e331d9dbd3ce98b19625b75ba38dd9ebc34cc
URL: https://github.com/llvm/llvm-project/commit/054e331d9dbd3ce98b19625b75ba38dd9ebc34cc
DIFF: https://github.com/llvm/llvm-project/commit/054e331d9dbd3ce98b19625b75ba38dd9ebc34cc.diff
LOG: [OpenCL] Supports optional program scope global variables in C++ for OpenCL 2021
Adds support for macro `__opencl_c_program_scope_global_variables`
in C++ for OpenCL 2021 enabling a respective optional core feature
from OpenCL 3.0.
This change aims to achieve compatibility between C++ for OpenCL
2021 and OpenCL 3.0.
Differential Revision: https://reviews.llvm.org/D109305
Added:
Modified:
clang/include/clang/Basic/OpenCLOptions.h
clang/test/SemaOpenCL/storageclass.cl
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/OpenCLOptions.h b/clang/include/clang/Basic/OpenCLOptions.h
index 4bc568802584..d6cb1a210519 100644
--- a/clang/include/clang/Basic/OpenCLOptions.h
+++ b/clang/include/clang/Basic/OpenCLOptions.h
@@ -80,7 +80,7 @@ class OpenCLOptions {
// C++ for OpenCL inherits rule from OpenCL C v2.0.
bool areProgramScopeVariablesSupported(const LangOptions &Opts) const {
return Opts.getOpenCLCompatibleVersion() == 200 ||
- (Opts.OpenCLVersion == 300 &&
+ (Opts.getOpenCLCompatibleVersion() == 300 &&
isSupported("__opencl_c_program_scope_global_variables", Opts));
}
diff --git a/clang/test/SemaOpenCL/storageclass.cl b/clang/test/SemaOpenCL/storageclass.cl
index 77880d1e3009..030d9c5ba54f 100644
--- a/clang/test/SemaOpenCL/storageclass.cl
+++ b/clang/test/SemaOpenCL/storageclass.cl
@@ -3,6 +3,10 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
static constant int G1 = 0;
constant int G2 = 0;
@@ -43,19 +47,23 @@ static private float g_private_static_var = 0;
#endif
static generic float g_generic_static_var = 0;
-#if (__OPENCL_C_VERSION__ < 300)
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
// expected-error at -3 {{program scope variable must reside in constant address space}}
-#elif (__OPENCL_C_VERSION__ == 300)
- #if !defined(__opencl_c_generic_address_space)
-// expected-error at -6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
- #endif
- #if !defined(__opencl_c_program_scope_global_variables)
-// expected-error at -9 {{program scope variable must reside in constant address space}}
- #endif
- #if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
-// expected-error at -12 {{program scope variable must reside in global or constant address space}}
- #endif
+#elif (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
+#if !defined(__opencl_c_generic_address_space)
+#if (__OPENCL_C_VERSION__ == 300)
+// expected-error at -7 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+#elif (__OPENCL_CPP_VERSION__ == 202100)
+// expected-error at -9 {{C++ for OpenCL version 2021 does not support the 'generic' type qualifier}}
+#endif
+#endif
+#if !defined(__opencl_c_program_scope_global_variables)
+// expected-error at -13 {{program scope variable must reside in constant address space}}
+#endif
+#if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
+// expected-error at -16 {{program scope variable must reside in global or constant address space}}
+#endif
#endif
extern float g_implicit_extern_var;
@@ -85,32 +93,36 @@ extern private float g_private_extern_var;
#endif
extern generic float g_generic_extern_var;
-#if (__OPENCL_C_VERSION__ < 300)
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
// expected-error at -3 {{extern variable must reside in constant address space}}
-#elif (__OPENCL_C_VERSION__ == 300)
- #if !defined(__opencl_c_generic_address_space)
-// expected-error at -6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
- #endif
- #if !defined(__opencl_c_program_scope_global_variables)
-// expected-error at -9 {{extern variable must reside in constant address space}}
- #endif
- #if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
-// expected-error at -12 {{extern variable must reside in global or constant address space}}
- #endif
+#elif (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
+#if !defined(__opencl_c_generic_address_space)
+#if (__OPENCL_C_VERSION__ == 300)
+// expected-error at -7 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+#elif (__OPENCL_CPP_VERSION__ == 202100)
+// expected-error at -9 {{C++ for OpenCL version 2021 does not support the 'generic' type qualifier}}
+#endif
+#endif
+#if !defined(__opencl_c_program_scope_global_variables)
+// expected-error at -13 {{extern variable must reside in constant address space}}
+#endif
+#if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
+// expected-error at -16 {{extern variable must reside in global or constant address space}}
+#endif
#endif
void kernel foo(int x) {
// static is not allowed at local scope before CL2.0
static int S1 = 5;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{variables in function scope cannot be declared static}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{static local variable must reside in constant address space}}
#endif
static constant int S2 = 5;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{variables in function scope cannot be declared static}}
#endif
@@ -122,7 +134,12 @@ void kernel foo(int x) {
constant int L1 = 42; // expected-error {{variables in the constant address space can only be declared in the outermost scope of a kernel function}}
}
- auto int L3 = 7; // expected-error-re{{OpenCL C version {{1.2|3.0}} does not support the 'auto' storage class specifier}}
+ auto int L3 = 7;
+#if (__OPENCL_CPP_VERSION__ == 202100)
+// expected-error at -2{{C++ for OpenCL version 2021 does not support the 'auto' storage class specifier}}
+#else
+// expected-error-re at -4{{OpenCL C version {{1.2|3.0}} does not support the 'auto' storage class specifier}}
+#endif
global int L4; // expected-error{{function scope variable cannot be declared in global address space}}
__attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}}
@@ -151,26 +168,26 @@ void f() {
}
static float l_implicit_static_var = 0;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{variables in function scope cannot be declared static}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{static local variable must reside in constant address space}}
#endif
static constant float l_constant_static_var = 0;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{variables in function scope cannot be declared static}}
#endif
static global float l_global_static_var = 0;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{variables in function scope cannot be declared static}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{static local variable must reside in constant address space}}
#endif
static local float l_local_static_var = 0;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{variables in function scope cannot be declared static}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{static local variable must reside in constant address space}}
@@ -179,7 +196,7 @@ void f() {
#endif
static private float l_private_static_var = 0;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{variables in function scope cannot be declared static}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{static local variable must reside in constant address space}}
@@ -188,23 +205,27 @@ void f() {
#endif
static generic float l_generic_static_var = 0;
-#if (__OPENCL_C_VERSION__ < 300)
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
// expected-error at -3 {{variables in function scope cannot be declared static}}
-#elif (__OPENCL_C_VERSION__ == 300)
- #if !defined(__opencl_c_generic_address_space)
-// expected-error at -6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
- #endif
- #if !defined(__opencl_c_program_scope_global_variables)
-// expected-error at -9 {{static local variable must reside in constant address space}}
- #endif
- #if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
-// expected-error at -12 {{static local variable must reside in global or constant address space}}
- #endif
+#elif (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
+#if !defined(__opencl_c_generic_address_space)
+#if (__OPENCL_C_VERSION__ == 300)
+// expected-error at -7 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+#elif (__OPENCL_CPP_VERSION__ == 202100)
+// expected-error at -9 {{C++ for OpenCL version 2021 does not support the 'generic' type qualifier}}
+#endif
+#endif
+#if !defined(__opencl_c_program_scope_global_variables)
+// expected-error at -13 {{static local variable must reside in constant address space}}
+#endif
+#if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
+// expected-error at -16 {{static local variable must reside in global or constant address space}}
+#endif
#endif
extern float l_implicit_extern_var;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{extern variable must reside in constant address space}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{extern variable must reside in constant address space}}
@@ -213,14 +234,14 @@ void f() {
extern constant float l_constant_extern_var;
extern global float l_global_extern_var;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{extern variable must reside in constant address space}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{extern variable must reside in constant address space}}
#endif
extern local float l_local_extern_var;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{extern variable must reside in constant address space}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{extern variable must reside in constant address space}}
@@ -229,7 +250,7 @@ void f() {
#endif
extern private float l_private_extern_var;
-#if __OPENCL_C_VERSION__ < 300
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{extern variable must reside in constant address space}}
#elif !defined(__opencl_c_program_scope_global_variables)
// expected-error at -4 {{extern variable must reside in constant address space}}
@@ -238,18 +259,22 @@ void f() {
#endif
extern generic float l_generic_extern_var;
-#if (__OPENCL_C_VERSION__ < 300)
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300)
// expected-error at -2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
// expected-error at -3 {{extern variable must reside in constant address space}}
-#elif (__OPENCL_C_VERSION__ == 300)
- #if !defined(__opencl_c_generic_address_space)
-// expected-error at -6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
- #endif
- #if !defined(__opencl_c_program_scope_global_variables)
-// expected-error at -9 {{extern variable must reside in constant address space}}
- #endif
- #if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
-// expected-error at -12 {{extern variable must reside in global or constant address space}}
- #endif
+#elif (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
+#if !defined(__opencl_c_generic_address_space)
+#if (__OPENCL_C_VERSION__ == 300)
+// expected-error at -7 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+#elif (__OPENCL_CPP_VERSION__ == 202100 && !defined(__opencl_c_generic_address_space))
+// expected-error at -9 {{C++ for OpenCL version 2021 does not support the 'generic' type qualifier}}
+#endif
+#endif
+#if !defined(__opencl_c_program_scope_global_variables)
+// expected-error at -13 {{extern variable must reside in constant address space}}
+#endif
+#if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
+// expected-error at -16 {{extern variable must reside in global or constant address space}}
+#endif
#endif
}
More information about the cfe-commits
mailing list