c-common.h (same_scalar_type_ignoring_signedness): Protoize.
authorAldy Hernandez <aldyh@redhat.com>
Wed, 15 Jun 2005 10:33:51 +0000 (10:33 +0000)
committerAldy Hernandez <aldyh@gcc.gnu.org>
Wed, 15 Jun 2005 10:33:51 +0000 (10:33 +0000)
* c-common.h (same_scalar_type_ignoring_signedness): Protoize.

* c-common.c (same_scalar_type_ignoring_signedness): New.

* c-typeck.c (build_binary_op): Check compatability of vector
types.  Move error report after switch.
Do not clobber code[01] on *_DIV_EXPR case.

* testsuite/gcc.dg/simd-1.c: Update error messages.
* testsuite/gcc.dg/simd-1b.c: Re-enable tests.  Update error
messages.
* testsuite/gcc.dg/simd-2.c: Update error messages.
* testsuite/gcc.dg/simd-4.c: New.

From-SVN: r100976

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/simd-1.c
gcc/testsuite/gcc.dg/simd-1b.c
gcc/testsuite/gcc.dg/simd-2.c
gcc/testsuite/gcc.dg/simd-4.c [new file with mode: 0644]

index c37f31b..d1fb305 100644 (file)
@@ -1,3 +1,19 @@
+2005-06-15  Aldy Hernandez  <aldyh@redhat.com>
+
+       * c-common.h (same_scalar_type_ignoring_signedness): Protoize.
+
+       * c-common.c (same_scalar_type_ignoring_signedness): New.
+
+       * c-typeck.c (build_binary_op): Check compatability of vector
+       types.  Move error report after switch.
+       Do not clobber code[01] on *_DIV_EXPR case.
+
+       * testsuite/gcc.dg/simd-1.c: Update error messages.
+       * testsuite/gcc.dg/simd-1b.c: Re-enable tests.  Update error
+       messages.
+       * testsuite/gcc.dg/simd-2.c: Update error messages.
+       * testsuite/gcc.dg/simd-4.c: New.
+
 2005-06-15  Bernd Schmidt  <bernd.schmidt@analog.com>
 
        * Makefile.in (local-alloc.o): Depend on $(GGC_H) and reload.h.
index 237f7d3..b7263aa 100644 (file)
@@ -6030,4 +6030,19 @@ resolve_overloaded_builtin (tree function, tree params)
     }
 }
 
+/* Ignoring their sign, return true if two scalar types are the same.  */
+bool
+same_scalar_type_ignoring_signedness (tree t1, tree t2)
+{
+  enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
+
+  gcc_assert ((c1 == INTEGER_TYPE || c1 == REAL_TYPE)
+             && (c2 == INTEGER_TYPE || c2 == REAL_TYPE));
+
+  /* Equality works here because c_common_signed_type uses
+     TYPE_MAIN_VARIANT.  */
+  return lang_hooks.types.signed_type (t1)
+    == lang_hooks.types.signed_type (t2);
+}
+
 #include "gt-c-common.h"
index 04b4346..2c59460 100644 (file)
@@ -657,6 +657,7 @@ extern tree convert_and_check (tree, tree);
 extern void overflow_warning (tree);
 extern void unsigned_conversion_warning (tree, tree);
 extern bool c_determine_visibility (tree);
+extern bool same_scalar_type_ignoring_signedness (tree, tree);
 
 #define c_sizeof(T)  c_sizeof_or_alignof_type (T, true, 1)
 #define c_alignof(T) c_sizeof_or_alignof_type (T, false, 1)
index fe56cf4..445193d 100644 (file)
@@ -7548,12 +7548,14 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
          && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
              || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
        {
+         enum tree_code tcode0 = code0, tcode1 = code1;
+
          if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
-           code0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
+           tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
          if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
-           code1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
+           tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
 
-         if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
+         if (!(tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE))
            resultcode = RDIV_EXPR;
          else
            /* Although it would be tempting to shorten always here, that
@@ -7793,6 +7795,15 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
     return error_mark_node;
 
+  if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
+      && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
+         || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
+                                                   TREE_TYPE (type1))))
+    {
+      binary_op_error (code);
+      return error_mark_node;
+    }
+
   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
        || code0 == VECTOR_TYPE)
       &&
index 216b331..d6e6a64 100644 (file)
@@ -1,3 +1,10 @@
+2005-06-15  Aldy Hernandez  <aldyh@redhat.com>
+
+       * gcc.dg/simd-1.c: Update error messages.
+       * gcc.dg/simd-1b.c: Re-enable tests.  Update error messages.
+       * gcc.dg/simd-2.c: Update error messages.
+       * gcc.dg/simd-4.c: New.
+
 2005-06-15  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/20678
index e36c5be..faf33dd 100644 (file)
@@ -54,8 +54,8 @@ hanneke ()
   a = -b;
 
   /* Operators on incompatible SIMD types.  */
-  a = b + c; /* { dg-error "can't convert between vector values of different size" } */
-  a = b - c; /* { dg-error "can't convert between vector values of different size" } */
-  a = b * c; /* { dg-error "can't convert between vector values of different size" } */
-  a = b / c; /* { dg-error "can't convert between vector values of different size" } */
+  a = b + c; /* { dg-error "invalid operands to binary +" } */
+  a = b - c; /* { dg-error "invalid operands to binary -" } */
+  a = b * c; /* { dg-error "invalid operands to binary *" } */
+  a = b / c; /* { dg-error "invalid operands to binary /" } */
 }
index d40fb04..56d94b9 100644 (file)
@@ -14,23 +14,23 @@ void
 hanneke ()
 {
   /* Operators on compatible SIMD types.  */
-  a %= b; /* { dg-bogus "invalid operands to binary %" "" { xfail *-*-* } } */
+  a %= b; /* { dg-error "invalid operands to binary %" } */
   c &= d;
   a |= b;
   c ^= d;
-  a >>= b; /* { dg-bogus "invalid operands to binary >>" "" { xfail *-*-* } } */
-  c <<= d; /* { dg-bogus "invalid operands to binary <<" "" { xfail *-*-* } } */
+  a >>= b; /* { dg-error "invalid operands to binary >>" } */
+  c <<= d; /* { dg-error "invalid operands to binary <<" } */
   a = +b;
   c = ~d;
 
   /* Operators on incompatible SIMD types.  */
-/*  a = b % c;  { dg*error "can't convert between vector values of different size" } */
-  a = b % c; /* { dg-bogus "invalid operands to binary %" "" { xfail *-*-* } } */
-  d = c & b; /* { dg-error "can't convert between vector values of different size" } */
-  a = b | c; /* { dg-error "can't convert between vector values of different size" } */
-  d = c ^ b; /* { dg-error "can't convert between vector values of different size" } */
-/*  a = b >> c;  { dg*error "can't convert between vector values of different size" } */
-  a = b >> c; /* { dg-bogus "invalid operands to binary >>" "" { xfail *-*-* } } */
-/*  d = c << b;  { dg*error "can't convert between vector values of different size" } */
-  d = c << b; /* { dg-bogus "invalid operands to binary <<" "" { xfail *-*-* } } */
+  a = b % c; /* { dg-error "invalid operands to binary" } */
+  a = b % c; /* { dg-error "invalid operands to binary" } */
+  d = c & b; /* { dg-error "invalid operands to binary" } */
+  a = b | c; /* { dg-error "invalid operands to binary" } */
+  d = c ^ b; /* { dg-error "invalid operands to binary" } */
+  a = b >> c; /*  { dg-error "invalid operands to binary" } */
+  a = b >> c; /* { dg-error "invalid operands to binary" } */
+  d = c << b; /* { dg-error "invalid operands to binary" } */
+  d = c << b; /* { dg-error "invalid operands to binary" } */
 }
index 20d4a07..09e28a7 100644 (file)
@@ -33,11 +33,10 @@ hanneke ()
   foo = a; /* { dg-error "incompatible types in assignment" } */
 
   /* Casted assignment between scalar and SIMD of same size.  */
-  foo = (typeof (foo)) foo2; /* { dg-bogus "aggregate value used where a float was expected" "" { xfail *-*-* } } */
+  foo = (typeof (foo)) foo2; /* { dg-error "aggregate value used where a float was expected" } */
 
   /* Casted assignment between scalar and SIMD of different size.  */
-/*  foo1 = (typeof (foo1)) foo2;  { dg*error "can't convert between vector values of different size" } */
-  foo1 = (typeof (foo1)) foo2; /* { dg-bogus "aggregate value used where a float was expected" "" { xfail *-*-* } } */
+  foo1 = (typeof (foo1)) foo2; /* { dg-error "aggregate value used where a float was expected" } */
 
   /* Operators on compatible SIMD types.  */
   a += b + b;
@@ -48,8 +47,8 @@ hanneke ()
   c = -d;
 
   /* Operators on incompatible SIMD types.  */
-  a = b + c; /* { dg-error "can't convert between vector values of different size" } */
-  a = b - c; /* { dg-error "can't convert between vector values of different size" } */
-  a = b * c; /* { dg-error "can't convert between vector values of different size" } */
-  a = b / c; /* { dg-error "can't convert between vector values of different size" } */
+  a = b + c; /* { dg-error "invalid operands to binary" } */
+  a = b - c; /* { dg-error "invalid operands to binary" } */
+  a = b * c; /* { dg-error "invalid operands to binary" } */
+  a = b / c; /* { dg-error "invalid operands to binary" } */
 }
diff --git a/gcc/testsuite/gcc.dg/simd-4.c b/gcc/testsuite/gcc.dg/simd-4.c
new file mode 100644 (file)
index 0000000..f7b28d4
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+typedef int myint;
+
+float __attribute__((vector_size(16))) b;
+int __attribute__((vector_size(16))) d;
+myint __attribute__((vector_size(16))) d2;
+unsigned int __attribute__((vector_size(16))) e;
+
+void foo()
+{
+       b + d; /* { dg-error "invalid operands to binary" } */
+       d += e;
+       d2 += d;
+}