[PATCH] D33732: Catch invalid bitwise operation on vector of floats

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 31 11:11:30 PDT 2017


sepavloff created this revision.

Bitwise complement applied to vector of floats described with
attribute `ext_vector_type` is not diagnosed as error. Attempt to
compile such construct causes assertion violation in Instruction.cpp.
With this change the complement is treated similar to the case of
vector type described with attribute `vector_size`.


https://reviews.llvm.org/D33732

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/types.c


Index: test/Sema/types.c
===================================================================
--- test/Sema/types.c
+++ test/Sema/types.c
@@ -88,3 +88,8 @@
 int &*_Atomic null_type_0; // expected-error {{expected identifier or '('}}
 int &*__restrict__ null_type_1; // expected-error {{expected identifier or '('}}
 int ^_Atomic null_type_2; // expected-error {{block pointer to non-function type is invalid}}
+
+typedef float __attribute__((ext_vector_type(4)))  float4;
+float4 test3(float4 x) {
+  return ~x; // expected-error{{invalid argument type 'float4' (vector of 4 'float' values) to unary expression}}
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -11951,16 +11951,13 @@
           << resultType << Input.get()->getSourceRange();
     else if (resultType->hasIntegerRepresentation())
       break;
-    else if (resultType->isExtVectorType()) {
-      if (Context.getLangOpts().OpenCL) {
-        // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate
-        // on vector float types.
-        QualType T = resultType->getAs<ExtVectorType>()->getElementType();
-        if (!T->isIntegerType())
-          return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
-                           << resultType << Input.get()->getSourceRange());
-      }
-      break;
+    else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) {
+      // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate
+      // on vector float types.
+      QualType T = resultType->getAs<ExtVectorType>()->getElementType();
+      if (!T->isIntegerType())
+        return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
+                          << resultType << Input.get()->getSourceRange());
     } else {
       return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
                        << resultType << Input.get()->getSourceRange());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33732.100891.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170531/bbc9410c/attachment.bin>


More information about the cfe-commits mailing list