]> granicus.if.org Git - clang/commitdiff
[Sema] Gcc compatibility of vector shift
authorAndrey Bokhanko <andreybokhanko@gmail.com>
Wed, 19 Oct 2016 12:06:10 +0000 (12:06 +0000)
committerAndrey Bokhanko <andreybokhanko@gmail.com>
Wed, 19 Oct 2016 12:06:10 +0000 (12:06 +0000)
Gcc prints error if elements of left and right parts of a shift have different
sizes. This patch is provided the GCC compatibility.

Patch by Vladimir Yakovlev.

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

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/CodeGen/vecshift.c
test/Sema/vecshift.c

index e274b464652c0c45137bd2de94c4486798ae9cf8..e04ead16d80893a42581740bab95ea671cf0b800 100644 (file)
@@ -2305,6 +2305,9 @@ def err_typecheck_vector_not_convertable_non_scalar : Error<
   "cannot convert between vector and non-scalar values (%0 and %1)">;
 def err_typecheck_vector_lengths_not_equal : Error<
   "vector operands do not have the same number of elements (%0 and %1)">;
+def warn_typecheck_vector_element_sizes_not_equal : Warning<
+  "vector operands do not have the same elements sizes (%0 and %1)">,
+  InGroup<DiagGroup<"vec-elem-size">>, DefaultError;
 def err_ext_vector_component_exceeds_length : Error<
   "vector component access exceeds type %0">;
 def err_ext_vector_component_name_illegal : Error<
index 40b5512523f1189d4f5b713b311b16acfac192fc..15564918b376d825c08720eb847977a0c7d2eebc 100644 (file)
@@ -8790,6 +8790,16 @@ static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS,
         << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
       return QualType();
     }
+    if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) {
+      const BuiltinType *LHSBT = LHSEleType->getAs<clang::BuiltinType>();
+      const BuiltinType *RHSBT = RHSEleType->getAs<clang::BuiltinType>();
+      if (LHSBT != RHSBT &&
+          S.Context.getTypeSize(LHSBT) != S.Context.getTypeSize(RHSBT)) {
+        S.Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal)
+            << LHS.get()->getType() << RHS.get()->getType()
+            << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+      }
+    }
   } else {
     // ...else expand RHS to match the number of elements in LHS.
     QualType VecTy =
index 67ab4a5ba2833f9de52906ad241661d6b8d21bb3..1fa047cd30b9edc03de841989d28614a67c02176 100644 (file)
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1  -Wno-error-vec-elem-size -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1  -Wno-error-vec-elem-size -DEXT -emit-llvm %s -o - | FileCheck %s
 
+#ifdef EXT
 typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
 typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
 typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
@@ -12,6 +14,20 @@ typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+#else
+typedef __attribute__((vector_size(8))) char vector_char8;
+typedef __attribute__((vector_size(16))) short vector_short8;
+typedef __attribute__((vector_size(32))) int vector_int8;
+typedef __attribute__((vector_size(8))) unsigned char vector_uchar8;
+typedef __attribute__((vector_size(16))) unsigned short vector_ushort8;
+typedef __attribute__((vector_size(32))) unsigned int vector_uint8;
+typedef __attribute__((vector_size(4))) char vector_char4;
+typedef __attribute__((vector_size(4))) short vector_short4;
+typedef __attribute__((vector_size(16))) int vector_int4;
+typedef __attribute__((vector_size(4))) unsigned char vector_uchar4;
+typedef __attribute__((vector_size(8))) unsigned short vector_ushort4;
+typedef __attribute__((vector_size(16))) unsigned int vector_uint4;
+#endif
 
 char c;
 short s;
index 59a599f85fe11e2239483ebb58fd1b2c27c66e7f..7b6a30ad60ddb35e542bb804e0df91bbc1b9b2e1 100644 (file)
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-error-vec-elem-size -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DEXT -DERR -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DEXT -Wno-error-vec-elem-size -verify %s
 
+#ifdef EXT
 typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
 typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
 typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
@@ -12,6 +16,20 @@ typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+#else
+typedef __attribute__((vector_size(8))) char vector_char8;
+typedef __attribute__((vector_size(16))) short vector_short8;
+typedef __attribute__((vector_size(32))) int vector_int8;
+typedef __attribute__((vector_size(8))) unsigned char vector_uchar8;
+typedef __attribute__((vector_size(16))) unsigned short vector_ushort8;
+typedef __attribute__((vector_size(32))) unsigned int vector_uint8;
+typedef __attribute__((vector_size(4))) char vector_char4;
+typedef __attribute__((vector_size(4))) short vector_short4;
+typedef __attribute__((vector_size(16))) int vector_int4;
+typedef __attribute__((vector_size(4))) unsigned char vector_uchar4;
+typedef __attribute__((vector_size(8))) unsigned short vector_ushort4;
+typedef __attribute__((vector_size(16))) unsigned int vector_uint4;
+#endif
 
 char c;
 short s;
@@ -48,16 +66,30 @@ void foo() {
   vus8 = 1 << vus8;
 
   vc8 = vc8 << vc8;
-  vi8 = vi8 << vuc8;
-  vuc8 = vuc8 << vi8;
-  vus8 = vus8 << vui8;
-  vui8 = vui8 << vs8;
+#ifdef ERR
+  vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}}
+  vuc8 = vuc8 << vi8; // expected-error {{vector operands do not have the same elements sizes}}
+  vus8 = vus8 << vui8; // expected-error {{vector operands do not have the same elements sizes}}
+  vui8 = vui8 << vs8; // expected-error {{vector operands do not have the same elements sizes}}
+#else
+  vi8 = vi8 << vuc8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vuc8 = vuc8 << vi8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vus8 = vus8 << vui8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vui8 = vui8 << vs8; // expected-warning {{vector operands do not have the same elements sizes}}
+#endif
 
   vc8 <<= vc8;
-  vi8 <<= vuc8;
-  vuc8 <<= vi8;
-  vus8 <<= vui8;
-  vui8 <<= vs8;
+#ifdef ERR
+  vi8 <<= vuc8; // expected-error {{vector operands do not have the same elements sizes}}
+  vuc8 <<= vi8; // expected-error {{vector operands do not have the same elements sizes}}
+  vus8 <<= vui8; // expected-error {{vector operands do not have the same elements sizes}}
+  vui8 <<= vs8; // expected-error {{vector operands do not have the same elements sizes}}
+#else
+  vi8 <<= vuc8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vuc8 <<= vi8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vus8 <<= vui8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vui8 <<= vs8; // expected-warning {{vector operands do not have the same elements sizes}}
+#endif
 
   c <<= vc8; // expected-error {{assigning to 'char' from incompatible type}}
   i <<= vuc8; // expected-error {{assigning to 'int' from incompatible type}}