]> granicus.if.org Git - clang/commitdiff
[OpenCL] Restrict swizzle length check to OpenCL mode
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Tue, 17 Oct 2017 17:54:57 +0000 (17:54 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Tue, 17 Oct 2017 17:54:57 +0000 (17:54 +0000)
Changes behavior introduced in r298369 to only error out on
vector component invalid length access on OpenCL mode.

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

rdar://problem/33568748

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316016 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprMember.cpp
test/Sema/vector_swizzle_length.c [new file with mode: 0644]
test/SemaOpenCL/vector_swizzle_length.cl

index c3561f6400a1aa645be1cdd1610f856455fd657a..bf4cb53b7d87148c4846335368885fdcb6e9ad34 100644 (file)
@@ -384,7 +384,9 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK,
     }
   }
 
-  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)
diff --git a/test/Sema/vector_swizzle_length.c b/test/Sema/vector_swizzle_length.c
new file mode 100644 (file)
index 0000000..5e6b1e7
--- /dev/null
@@ -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 94e3f654d5d9ca548319ffd767915aeea2230fa8..4dbb5bd76ee0a7cd4309b746841c1dbc32df15d9 100644 (file)
@@ -1,4 +1,4 @@
-// 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)));