r198680 - For areVectorOperandsLaxBitCastable(), only return false if both opearands are vector types

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Jan 6 23:59:32 PST 2014


Author: akirtzidis
Date: Tue Jan  7 01:59:31 2014
New Revision: 198680

URL: http://llvm.org/viewvc/llvm-project?rev=198680&view=rev
Log:
For areVectorOperandsLaxBitCastable(), only return false if both opearands are vector types
and add a diagnostic when the operand is a vector and non-scalar value.

rdar://15722301

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/vector-casts.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=198680&r1=198679&r2=198680&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan  7 01:59:31 2014
@@ -1869,6 +1869,8 @@ def err_attribute_zero_size : Error<"zer
 def err_attribute_size_too_large : Error<"vector size too large">;
 def err_typecheck_vector_not_convertable : Error<
   "can't convert between vector values of different size (%0 and %1)">;
+def err_typecheck_vector_not_convertable_non_scalar : Error<
+  "can't convert between vector and non-scalar values (%0 and %1)">;
 def err_ext_vector_component_exceeds_length : Error<
   "vector component access exceeds type %0">;
 def err_ext_vector_component_name_illegal : Error<

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=198680&r1=198679&r2=198680&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan  7 01:59:31 2014
@@ -6617,6 +6617,9 @@ static bool areVectorOperandsLaxBitCasta
   if (!Ctx.getLangOpts().LaxVectorConversions)
     return false;
 
+  if (!LHSType->isVectorType() || !RHSType->isVectorType())
+    return false;
+
   unsigned LHSSize = Ctx.getTypeSize(LHSType);
   unsigned RHSSize = Ctx.getTypeSize(RHSType);
   if (LHSSize != RHSSize)
@@ -6628,20 +6631,13 @@ static bool areVectorOperandsLaxBitCasta
   // Make sure such width is the same between the types, otherwise we may end
   // up with an invalid bitcast.
   unsigned LHSIRSize, RHSIRSize;
-  if (LHSType->isVectorType()) {
-    const VectorType *Vec = LHSType->getAs<VectorType>();
-    LHSIRSize = Vec->getNumElements() *
-        Ctx.getTypeSize(Vec->getElementType());
-  } else {
-    LHSIRSize = LHSSize;
-  }
-  if (RHSType->isVectorType()) {
-    const VectorType *Vec = RHSType->getAs<VectorType>();
-    RHSIRSize = Vec->getNumElements() *
-        Ctx.getTypeSize(Vec->getElementType());
-  } else {
-    RHSIRSize = RHSSize;
-  }
+  const VectorType *LVec = LHSType->getAs<VectorType>();
+  LHSIRSize = LVec->getNumElements() *
+      Ctx.getTypeSize(LVec->getElementType());
+  const VectorType *RVec = RHSType->getAs<VectorType>();
+  RHSIRSize = RVec->getNumElements() *
+      Ctx.getTypeSize(RVec->getElementType());
+
   if (LHSIRSize != RHSIRSize)
     return false;
 
@@ -6692,6 +6688,14 @@ QualType Sema::CheckVectorOperands(ExprR
     return LHSType;
   }
 
+  if (!(LHSType->isVectorType() || LHSType->isScalarType()) ||
+      !(RHSType->isVectorType() || RHSType->isScalarType())) {
+    Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
+    << LHS.get()->getType() << RHS.get()->getType()
+    << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+    return QualType();
+  }
+
   // Canonicalize the ExtVector to the LHS, remember if we swapped so we can
   // swap back (so that we don't reverse the inputs to a subtract, for instance.
   bool swapped = false;

Modified: cfe/trunk/test/SemaCXX/vector-casts.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vector-casts.cpp?rev=198680&r1=198679&r2=198680&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vector-casts.cpp (original)
+++ cfe/trunk/test/SemaCXX/vector-casts.cpp Tue Jan  7 01:59:31 2014
@@ -37,4 +37,12 @@ void f() {
   (void)(__v4hi)v8hi; // expected-error {{C-style cast from vector '__v8hi' to vector '__v4hi' of different size}}
 }
 
-
+struct testvec {
+  __v2si v;
+  void madd(const testvec& rhs) {
+    v = v + rhs; // expected-error {{can't convert between vector and non-scalar values}}
+  }
+  void madd2(testvec rhs) {
+    v = v + rhs; // expected-error {{can't convert between vector and non-scalar values}}
+  }
+};





More information about the cfe-commits mailing list