]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/10611 (operations on vector mode not recognized in C++)
authorAldy Hernandez <aldyh@redhat.com>
Sat, 11 Jun 2005 00:16:02 +0000 (00:16 +0000)
committerAldy Hernandez <aldyh@gcc.gnu.org>
Sat, 11 Jun 2005 00:16:02 +0000 (00:16 +0000)
PR c++/10611
* cp/cvt.c (build_expr_type_conversion): Same.
* cp/typeck.c (build_binary_op): Handle vectors.
(common_type): Same.
(type_after_usual_arithmetic_conversions): Same.
* testsuite/g++.dg/conversion/simd2.C: New.

From-SVN: r100834

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/cp/typeck.c

index 3197c669bfdd9ce9998709d2dca4ade39151ac00..50b59ed8ea32843d02899f9f3aeade2ab1263a16 100644 (file)
@@ -1,3 +1,12 @@
+2005-06-10  Aldy Hernandez  <aldyh@redhat.com>
+
+       PR c++/10611
+       * cvt.c (build_expr_type_conversion): Same.
+       * typeck.c (build_binary_op): Handle vectors.
+       (common_type): Same.
+       (type_after_usual_arithmetic_conversions): Same.
+       * testsuite/g++.dg/conversion/simd2.C: New.
+
 2005-06-08  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/21903
index 95fce0754f0931c11ac7c67365bbcb0f358ca11a..8276451cb10cb7c93db2026d0a28ff1477ebc433 100644 (file)
@@ -1029,6 +1029,7 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
          return expr;
        /* else fall through...  */
 
+      case VECTOR_TYPE:
       case BOOLEAN_TYPE:
        return (desires & WANT_INT) ? expr : NULL_TREE;
       case ENUMERAL_TYPE:
index 7f6e8b869ef07d936925d9f0cfd687b57c01425b..e0f6868a6d7e112ce6889ce9bd5c2021bf118553 100644 (file)
@@ -265,10 +265,12 @@ type_after_usual_arithmetic_conversions (tree t1, tree t2)
   /* FIXME: Attributes.  */
   my_friendly_assert (ARITHMETIC_TYPE_P (t1) 
                      || TREE_CODE (t1) == COMPLEX_TYPE
+                     || TREE_CODE (t1) == VECTOR_TYPE
                      || TREE_CODE (t1) == ENUMERAL_TYPE,
                      19990725);
   my_friendly_assert (ARITHMETIC_TYPE_P (t2) 
                      || TREE_CODE (t2) == COMPLEX_TYPE
+                     || TREE_CODE (t2) == VECTOR_TYPE
                      || TREE_CODE (t2) == ENUMERAL_TYPE,
                      19990725);
 
@@ -296,6 +298,16 @@ type_after_usual_arithmetic_conversions (tree t1, tree t2)
                                             attributes);
     }
 
+  if (code1 == VECTOR_TYPE)
+    {
+      /* When we get here we should have two vectors of the same size.
+        Just prefer the unsigned one if present.  */
+      if (TREE_UNSIGNED (t1))
+       return build_type_attribute_variant (t1, attributes);
+      else
+       return build_type_attribute_variant (t2, attributes);
+    }
+
   /* If only one is real, use it as the result.  */
   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
     return build_type_attribute_variant (t1, attributes);
@@ -745,9 +757,9 @@ common_type (tree t1, tree t2)
   code2 = TREE_CODE (t2);
 
   if ((ARITHMETIC_TYPE_P (t1) || code1 == ENUMERAL_TYPE
-       || code1 == COMPLEX_TYPE)
+       || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
       && (ARITHMETIC_TYPE_P (t2) || code2 == ENUMERAL_TYPE
-         || code2 == COMPLEX_TYPE))
+         || code2 == COMPLEX_TYPE || code2 == VECTOR_TYPE))
     return type_after_usual_arithmetic_conversions (t1, t2);
 
   else if ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
@@ -2878,9 +2890,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
     case ROUND_DIV_EXPR:
     case EXACT_DIV_EXPR:
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
-          || code0 == COMPLEX_TYPE)
+          || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
          && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
-             || code1 == COMPLEX_TYPE))
+             || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
        {
          if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1))
            warning ("division by zero in `%E / 0'", op0);
@@ -2907,7 +2919,8 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
     case BIT_AND_EXPR:
     case BIT_IOR_EXPR:
     case BIT_XOR_EXPR:
-      if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
+      if ((code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
+         || (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE))
        shorten = -1;
       break;
 
@@ -3158,12 +3171,17 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
       break;
     }
 
-  if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
-      &&
-      (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
+  if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
+       &&
+       (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
+      || (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE))
     {
       int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
 
+      if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
+          && !tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)))
+       error ("can't convert between vector values of different size");
+
       if (shorten || common || short_compare)
        result_type = common_type (type0, type1);