[PATCH] D21678: Fix For pr28288 - Error message in shift of vector values

Vladimir Yakovlev via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 30 22:41:07 PDT 2016


vbyakovl updated this revision to Diff 62464.

http://reviews.llvm.org/D21678

Files:
  llvm/tools/clang/lib/Sema/SemaExpr.cpp
  llvm/tools/clang/test/Sema/shift.c

Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp
===================================================================
--- llvm/tools/clang/lib/Sema/SemaExpr.cpp
+++ llvm/tools/clang/lib/Sema/SemaExpr.cpp
@@ -8592,11 +8592,10 @@
     << RHS.get()->getSourceRange();
 }
 
-/// \brief Return the resulting type when an OpenCL vector is shifted
+/// \brief Return the resulting type when a vector is shifted
 ///        by a scalar or vector shift amount.
-static QualType checkOpenCLVectorShift(Sema &S,
-                                       ExprResult &LHS, ExprResult &RHS,
-                                       SourceLocation Loc, bool IsCompAssign) {
+static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS,
+                                 SourceLocation Loc, bool IsCompAssign) {
   // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector.
   if (!LHS.get()->getType()->isVectorType()) {
     S.Diag(Loc, diag::err_shift_rhs_only_vector)
@@ -8636,9 +8635,8 @@
   }
 
   if (RHSVecTy) {
-    // OpenCL v1.1 s6.3.j says that for vector types, the operators
-    // are applied component-wise. So if RHS is a vector, then ensure
-    // that the number of elements is the same as LHS...
+    // For vector types, the operators are applied component-wise. So if RHS is
+    // a vector, then ensure that the number of elements is the same as LHS...
     if (RHSVecTy->getNumElements() != LHSVecTy->getNumElements()) {
       S.Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
         << LHS.get()->getType() << RHS.get()->getType()
@@ -8664,23 +8662,18 @@
   // Vector shifts promote their scalar inputs to vector type.
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType()) {
-    if (LangOpts.OpenCL)
-      return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign);
     if (LangOpts.ZVector) {
       // The shift operators for the z vector extensions work basically
-      // like OpenCL shifts, except that neither the LHS nor the RHS is
+      // like general shifts, except that neither the LHS nor the RHS is
       // allowed to be a "vector bool".
       if (auto LHSVecType = LHS.get()->getType()->getAs<VectorType>())
         if (LHSVecType->getVectorKind() == VectorType::AltiVecBool)
           return InvalidOperands(Loc, LHS, RHS);
       if (auto RHSVecType = RHS.get()->getType()->getAs<VectorType>())
         if (RHSVecType->getVectorKind() == VectorType::AltiVecBool)
           return InvalidOperands(Loc, LHS, RHS);
-      return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign);
     }
-    return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign,
-                               /*AllowBothBool*/true,
-                               /*AllowBoolConversions*/false);
+    return checkVectorShift(*this, LHS, RHS, Loc, IsCompAssign);
   }
 
   // Shifts don't perform usual arithmetic conversions, they just do integer
Index: llvm/tools/clang/test/Sema/shift.c
===================================================================
--- llvm/tools/clang/test/Sema/shift.c
+++ llvm/tools/clang/test/Sema/shift.c
@@ -67,3 +67,24 @@
     (void) (x >> 80); // no-warning
   (void) (x >> 80); // expected-warning {{shift count >= width of type}}
 }
+
+typedef unsigned vec16 __attribute__ ((vector_size (16)));
+typedef unsigned vec8 __attribute__ ((vector_size (8)));
+
+void
+vect_shift_1 (vec16 *x)
+{
+   *x = *x << 4 ;
+}
+
+void
+vect_shift_2 (vec16 *x,vec16 y)
+{
+   *x = *x << y ;
+}
+
+void
+vect_shift_3 (vec16 *x,vec8 y)
+{
+   *x = *x << y ; // expected-error {{vector operands do not have the same number of elements}}
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21678.62464.patch
Type: text/x-patch
Size: 3649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160701/a7899d7c/attachment-0001.bin>


More information about the cfe-commits mailing list