[OpenCL] Enables .rgba vector extension in C++ for OpenCL 2021
authorJustas Janickas <Justas.Janickas@arm.com>
Tue, 7 Sep 2021 13:32:05 +0000 (14:32 +0100)
committerJustas Janickas <Justas.Janickas@arm.com>
Tue, 14 Sep 2021 12:05:42 +0000 (13:05 +0100)
`.rgba` vector extension setting in C++ for OpenCL 2021 is now
performed analogously to OpenCL C 3.0. Test case added.

Differential Revision: https://reviews.llvm.org/D109370

clang/lib/Sema/SemaExprMember.cpp
clang/test/SemaOpenCL/ext_vectors.cl

index 92b7464..0f0dd8a 100644 (file)
@@ -340,7 +340,8 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK,
 
     // Emit a warning if an rgba selector is used earlier than OpenCL C 3.0.
     if (HasRGBA || (*compStr && IsRGBA(*compStr))) {
-      if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion < 300) {
+      if (S.getLangOpts().OpenCL &&
+          S.getLangOpts().getOpenCLCompatibleVersion() < 300) {
         const char *DiagBegin = HasRGBA ? CompName->getNameStart() : compStr;
         S.Diag(OpLoc, diag::ext_opencl_ext_vector_type_rgba_selector)
             << StringRef(DiagBegin, 1) << SourceRange(CompLoc);
index 7404f03..ce5b333 100644 (file)
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++1.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021
 
 typedef float float4 __attribute__((ext_vector_type(4)));
 
@@ -9,13 +10,13 @@ void test_ext_vector_accessors(float4 V) {
   V = V.wzyx;
 
   V = V.abgr;
-#if (__OPENCL_C_VERSION__ < 300)
+#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300) || (defined(__OPENCL_CPP_VERSION__) && __OPENCL_CPP_VERSION__ < 202100))
   // expected-warning@-2 {{vector component name 'a' is a feature from OpenCL version 3.0 onwards}}
 #endif
 
   V = V.xyzr;
   // expected-error@-1 {{illegal vector component name 'r'}}
-#if (__OPENCL_C_VERSION__ < 300)
+#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300) || (defined(__OPENCL_CPP_VERSION__) && __OPENCL_CPP_VERSION__ < 202100))
   // expected-warning@-3 {{vector component name 'r' is a feature from OpenCL version 3.0 onwards}}
 #endif
 }