Skip to content

Commit 09dc454

Browse files
committed
[OpenCL] Enables .rgba vector extension in C++ for OpenCL 2021
`.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
1 parent 44a8897 commit 09dc454

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK,
340340

341341
// Emit a warning if an rgba selector is used earlier than OpenCL C 3.0.
342342
if (HasRGBA || (*compStr && IsRGBA(*compStr))) {
343-
if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion < 300) {
343+
if (S.getLangOpts().OpenCL &&
344+
S.getLangOpts().getOpenCLCompatibleVersion() < 300) {
344345
const char *DiagBegin = HasRGBA ? CompName->getNameStart() : compStr;
345346
S.Diag(OpLoc, diag::ext_opencl_ext_vector_type_rgba_selector)
346347
<< StringRef(DiagBegin, 1) << SourceRange(CompLoc);

clang/test/SemaOpenCL/ext_vectors.cl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
33
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0
44
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++1.0
5+
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021
56

67
typedef float float4 __attribute__((ext_vector_type(4)));
78

89
void test_ext_vector_accessors(float4 V) {
910
V = V.wzyx;
1011

1112
V = V.abgr;
12-
#if (__OPENCL_C_VERSION__ < 300)
13+
#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300) || (defined(__OPENCL_CPP_VERSION__) && __OPENCL_CPP_VERSION__ < 202100))
1314
// expected-warning@-2 {{vector component name 'a' is a feature from OpenCL version 3.0 onwards}}
1415
#endif
1516

1617
V = V.xyzr;
1718
// expected-error@-1 {{illegal vector component name 'r'}}
18-
#if (__OPENCL_C_VERSION__ < 300)
19+
#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300) || (defined(__OPENCL_CPP_VERSION__) && __OPENCL_CPP_VERSION__ < 202100))
1920
// expected-warning@-3 {{vector component name 'r' is a feature from OpenCL version 3.0 onwards}}
2021
#endif
2122
}

0 commit comments

Comments
 (0)