uweigand created this revision.
uweigand added a reviewer: rsmith.
uweigand added a subscriber: cfe-commits.

Before the patch:

typedef unsigned int v4si __attribute__((ext_vector_type(4)));
void foo(v4si *ptr) { *ptr += 1.0f; }

would generate:

error: can't convert between vector values of different size ('v4si' (vector of 
4 'unsigned int' values) and 'float')
void foo(v4si *ptr) { *ptr += 1.0f; }
                      ~~~~ ^  ~~~~

This is a bit misleading, since the problem is a type mismatch between
the type of the scalar and the type of the vector elements, not a problem
with vectors of different size.  (E.g. the code is correct with "1.0f"
replaced by the like-sized "1".)  The patch changes the error to the more
generic:

error: invalid operands to binary expression ('v4si' (vector of 4 'unsigned 
int' values) and 'float')
void foo(v4si *ptr) { *ptr += 1.0f; }
                      ~~~~ ^  ~~~~

Original patch by Richard Sandiford.


http://reviews.llvm.org/D11151

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/ext_vector_casts.c
  test/SemaOpenCL/cond.cl

Index: test/SemaOpenCL/cond.cl
===================================================================
--- test/SemaOpenCL/cond.cl
+++ test/SemaOpenCL/cond.cl
@@ -89,7 +89,7 @@
 
 float2 ntest05(int2 C, int2 X, float Y)
 {
-  return C ? X : Y; // expected-error {{can't convert between vector values of 
different size ('int2' (vector of 2 'int' values) and 'float')}}
+  return C ? X : Y; // expected-error {{invalid operands to binary expression 
('int2' (vector of 2 'int' values) and 'float')}}
 }
 
 char2 ntest06(int2 C, char2 X, char2 Y)
Index: test/Sema/ext_vector_casts.c
===================================================================
--- test/Sema/ext_vector_casts.c
+++ test/Sema/ext_vector_casts.c
@@ -102,11 +102,11 @@
   vs = 65536 + vs; // expected-warning {{implicit conversion from 'int' to 
'short8' (vector of 8 'short' values) changes value from 65536 to 0}}
   vs = vs + i; // expected-warning {{implicit conversion loses integer 
precision}}
   vs = vs + 1;
-  vs = vs + 1.f; // expected-error {{can't convert between vector values of 
different size}}
+  vs = vs + 1.f; // expected-error {{invalid operands to binary expression}}
   
   vi = l + vi; // expected-warning {{implicit conversion loses integer 
precision}}
   vi = 1 + vi;
-  vi = vi + 2.0; // expected-error {{can't convert between vector values of 
different size}}
+  vi = vi + 2.0; // expected-error {{invalid operands to binary expression}}
   vi = vi + 0xffffffff; // expected-warning {{implicit conversion changes 
signedness}}
   
   vl = l + vl; // expected-warning {{implicit conversion changes signedness}}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -7338,6 +7338,11 @@
     return QualType();
   }
 
+  // Otherwise, if one is a vector and one isn't, treat it as a general invalid
+  // combination, rather than as an incompatibility between two vector sizes.
+  if (!LHSVecType || !RHSVecType)
+    return InvalidOperands(Loc, LHS, RHS);
+
   // Otherwise, use the generic diagnostic.
   Diag(Loc, diag::err_typecheck_vector_not_convertable)
     << LHSType << RHSType


Index: test/SemaOpenCL/cond.cl
===================================================================
--- test/SemaOpenCL/cond.cl
+++ test/SemaOpenCL/cond.cl
@@ -89,7 +89,7 @@
 
 float2 ntest05(int2 C, int2 X, float Y)
 {
-  return C ? X : Y; // expected-error {{can't convert between vector values of different size ('int2' (vector of 2 'int' values) and 'float')}}
+  return C ? X : Y; // expected-error {{invalid operands to binary expression ('int2' (vector of 2 'int' values) and 'float')}}
 }
 
 char2 ntest06(int2 C, char2 X, char2 Y)
Index: test/Sema/ext_vector_casts.c
===================================================================
--- test/Sema/ext_vector_casts.c
+++ test/Sema/ext_vector_casts.c
@@ -102,11 +102,11 @@
   vs = 65536 + vs; // expected-warning {{implicit conversion from 'int' to 'short8' (vector of 8 'short' values) changes value from 65536 to 0}}
   vs = vs + i; // expected-warning {{implicit conversion loses integer precision}}
   vs = vs + 1;
-  vs = vs + 1.f; // expected-error {{can't convert between vector values of different size}}
+  vs = vs + 1.f; // expected-error {{invalid operands to binary expression}}
   
   vi = l + vi; // expected-warning {{implicit conversion loses integer precision}}
   vi = 1 + vi;
-  vi = vi + 2.0; // expected-error {{can't convert between vector values of different size}}
+  vi = vi + 2.0; // expected-error {{invalid operands to binary expression}}
   vi = vi + 0xffffffff; // expected-warning {{implicit conversion changes signedness}}
   
   vl = l + vl; // expected-warning {{implicit conversion changes signedness}}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -7338,6 +7338,11 @@
     return QualType();
   }
 
+  // Otherwise, if one is a vector and one isn't, treat it as a general invalid
+  // combination, rather than as an incompatibility between two vector sizes.
+  if (!LHSVecType || !RHSVecType)
+    return InvalidOperands(Loc, LHS, RHS);
+
   // Otherwise, use the generic diagnostic.
   Diag(Loc, diag::err_typecheck_vector_not_convertable)
     << LHSType << RHSType
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to