[PATCH] D38868: [OpenCL] Restrict swizzle length check to OpenCL mode
Bruno Cardoso Lopes via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 13 13:18:13 PDT 2017
bruno updated this revision to Diff 118966.
bruno marked 2 inline comments as done.
bruno added a comment.
Update patch after Anastasia's suggestions
https://reviews.llvm.org/D38868
Files:
lib/Sema/SemaExprMember.cpp
test/Sema/vector_swizzle_length.c
test/SemaOpenCL/vector_swizzle_length.cl
Index: test/SemaOpenCL/vector_swizzle_length.cl
===================================================================
--- test/SemaOpenCL/vector_swizzle_length.cl
+++ test/SemaOpenCL/vector_swizzle_length.cl
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 -x cl %s -verify -pedantic -fsyntax-only
typedef float float8 __attribute__((ext_vector_type(8)));
void foo() {
- float8 f2 = (float8)(0, 0, 0, 0, 0, 0, 0, 0);
+ float8 f2 = (float8){0, 0, 0, 0, 0, 0, 0, 0};
f2.s01234; // expected-error {{vector component access has invalid length 5. Supported: 1,2,3,4,8,16}}
f2.xyzxy; // expected-error {{vector component access has invalid length 5. Supported: 1,2,3,4,8,16}}
Index: test/Sema/vector_swizzle_length.c
===================================================================
--- /dev/null
+++ test/Sema/vector_swizzle_length.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c %s -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
+
+typedef float float8 __attribute__((ext_vector_type(8)));
+
+void foo() {
+ float8 f2 = (float8){0, 0, 0, 0, 0, 0, 0, 0};
+ (void)f2.s01234;
+ (void)f2.xyzxy;
+}
Index: lib/Sema/SemaExprMember.cpp
===================================================================
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -384,7 +384,9 @@
}
}
- if (!HalvingSwizzle) {
+ // OpenCL mode requires swizzle length to be in accordance with accepted
+ // sizes. Clang however supports arbitrary lengths for other languages.
+ if (S.getLangOpts().OpenCL && !HalvingSwizzle) {
unsigned SwizzleLength = CompName->getLength();
if (HexSwizzle)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38868.118966.patch
Type: text/x-patch
Size: 1682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171013/e40861e7/attachment-0001.bin>
More information about the cfe-commits
mailing list