[PATCH] D38868: [OpenCL] Restrict swizzle length check to OpenCL mode

Bruno Cardoso Lopes via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 12 17:55:07 PDT 2017


bruno created this revision.
Herald added a subscriber: yaxunl.

Change behavior introduced in r298369 and only error out on vector component invalid length access on OpenCL mode.


https://reviews.llvm.org/D38868

Files:
  lib/Sema/SemaExprMember.cpp
  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,10 +1,17 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 -x cl %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 -x c %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};
 
+#if defined(__OPENCL_C_VERSION__)
     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}}
+#else
+    // expected-no-diagnostics
+    (void)f2.s01234;
+    (void)f2.xyzxy;
+#endif
 }
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.118871.patch
Type: text/x-patch
Size: 1432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171013/3dfef4f0/attachment-0001.bin>


More information about the cfe-commits mailing list