c-common.c (same_scalar_type_ignoring_signedness): Delete.
authorJoern Rennecke <joern.rennecke@embecosm.com>
Sun, 8 Sep 2013 06:16:24 +0000 (06:16 +0000)
committerJoern Rennecke <amylaar@gcc.gnu.org>
Sun, 8 Sep 2013 06:16:24 +0000 (07:16 +0100)
gcc/c-family:
        * c-common.c (same_scalar_type_ignoring_signedness): Delete.
        (vector_types_compatible_elements_p): New function.
        * c-common.h: (same_scalar_type_ignoring_signedness): Delete
declaration.
        (vector_types_compatible_elements_p): Declare.
gcc/c:
        * c-typeck.c (build_binary_op): Use vector_types_compatible_elements_p.
gcc/cp:
        * typeck.c (cp_build_binary_op): Use vector_types_compatible_elements_p.
gcc/testsuite:
        * c-c++-common/opaque-vector.c: New test.

From-SVN: r202364

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/opaque-vector.c [new file with mode: 0644]

index 2a0c4061198a5930a2701689257c25fa8f0dd047..95babfa743f1cb6adc6892a9ac3935714ba284c4 100644 (file)
@@ -1,3 +1,11 @@
+2013-09-08  Joern Rennecke  <joern.rennecke@embecosm.com>
+
+       * c-common.c (same_scalar_type_ignoring_signedness): Delete.
+       (vector_types_compatible_elements_p): New function.
+       * c-common.h: (same_scalar_type_ignoring_signedness): Delete
+       declaration.
+       (vector_types_compatible_elements_p): Declare.
+
 2013-09-04  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
        * c-pretty-print.h (c_pretty_printer::simple_type_specifier): Now
index 5d1a1c6c2ce7c87cac65b581d22c88b3529c5d8f..62aa9fcec2bb0192715ed698320c6adb56068fe5 100644 (file)
@@ -2199,6 +2199,14 @@ check_main_parameter_types (tree decl)
             "%q+D takes only zero or two arguments", decl);
 }
 
+/* vector_targets_convertible_p is used for vector pointer types.  The
+   callers perform various checks that the qualifiers are satisfactory,
+   while OTOH vector_targets_convertible_p ignores the number of elements
+   in the vectors.  That's fine with vector pointers as we can consider,
+   say, a vector of 8 elements as two consecutive vectors of 4 elements,
+   and that does not require and conversion of the pointer values.
+   In contrast, vector_types_convertible_p and
+   vector_types_compatible_elements_p are used for vector value types.  */
 /* True if pointers to distinct types T1 and T2 can be converted to
    each other without an explicit cast.  Only returns true for opaque
    vector types.  */
@@ -2213,6 +2221,17 @@ vector_targets_convertible_p (const_tree t1, const_tree t2)
   return false;
 }
 
+/* vector_types_convertible_p is used for vector value types.
+   It could in principle call vector_targets_convertible_p as a subroutine,
+   but then the check for vector type would be duplicated with its callers,
+   and also the purpose of vector_targets_convertible_p would become
+   muddled.
+   Where vector_types_convertible_p returns true, a conversion might still be
+   needed to make the types match.
+   In contrast, vector_targets_convertible_p is used for vector pointer
+   values, and vector_types_compatible_elements_p is used specifically
+   in the context for binary operators, as a check if use is possible without
+   conversion.  */
 /* True if vector types T1 and T2 can be converted to each other
    without an explicit cast.  If EMIT_LAX_NOTE is true, and T1 and T2
    can only be converted with -flax-vector-conversions yet that is not
@@ -10690,20 +10709,45 @@ resolve_overloaded_builtin (location_t loc, tree function,
     }
 }
 
-/* Ignoring their sign, return true if two scalar types are the same.  */
+/* vector_types_compatible_elements_p is used in type checks of vectors
+   values used as operands of binary operators.  Where it returns true, and
+   the other checks of the caller succeed (being vector types in he first
+   place, and matching number of elements), we can just treat the types
+   as essentially the same.
+   Contrast with vector_targets_convertible_p, which is used for vector
+   pointer types,  and vector_types_convertible_p, which will allow
+   language-specific matches under the control of flag_lax_vector_conversions,
+   and might still require a conversion.  */
+/* True if vector types T1 and T2 can be inputs to the same binary
+   operator without conversion.
+   We don't check the overall vector size here because some of our callers
+   want to give different error messages when the vectors are compatible
+   except for the element count.  */
+
 bool
-same_scalar_type_ignoring_signedness (tree t1, tree t2)
+vector_types_compatible_elements_p (tree t1, tree t2)
 {
+  bool opaque = TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2);
+  t1 = TREE_TYPE (t1);
+  t2 = TREE_TYPE (t2);
+
   enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
 
   gcc_assert ((c1 == INTEGER_TYPE || c1 == REAL_TYPE || c1 == FIXED_POINT_TYPE)
              && (c2 == INTEGER_TYPE || c2 == REAL_TYPE
                  || c2 == FIXED_POINT_TYPE));
 
+  t1 = c_common_signed_type (t1);
+  t2 = c_common_signed_type (t2);
   /* Equality works here because c_common_signed_type uses
      TYPE_MAIN_VARIANT.  */
-  return c_common_signed_type (t1)
-    == c_common_signed_type (t2);
+  if (t1 == t2)
+    return true;
+  if (opaque && c1 == c2
+      && (c1 == INTEGER_TYPE || c1 == REAL_TYPE)
+      && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
+    return true;
+  return false;
 }
 
 /* Check for missing format attributes on function pointers.  LTYPE is
index cc09dbc008fc85557a4db241c10b8b641ddea766..722ba6e5c1521f759f99f7465ec7f309794ecb67 100644 (file)
@@ -766,7 +766,7 @@ extern void warn_logical_operator (location_t, enum tree_code, tree,
                                   enum tree_code, tree, enum tree_code, tree);
 extern void check_main_parameter_types (tree decl);
 extern bool c_determine_visibility (tree);
-extern bool same_scalar_type_ignoring_signedness (tree, tree);
+extern bool vector_types_compatible_elements_p (tree, tree);
 extern void mark_valid_location_for_stdc_pragma (bool);
 extern bool valid_location_for_stdc_pragma_p (void);
 extern void set_float_const_decimal64 (void);
index 3401228c039d4f7caf2cc55e57a5042cfea056f3..1b4b29772943c09503c0a27329de6c2bafffc789 100644 (file)
@@ -1,3 +1,7 @@
+2013-09-08  Joern Rennecke  <joern.rennecke@embecosm.com>
+
+       * c-typeck.c (build_binary_op): Use vector_types_compatible_elements_p.
+
 2013-09-03  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
        * c-objc-common.c (c_tree_printer): Tidy.
index f29ca049649a6611965ee08bae637586fb0c7abe..e52533ecd6d3b35054e0df9b0571d8d3e28f9c59 100644 (file)
@@ -9987,7 +9987,7 @@ build_binary_op (location_t location, enum tree_code code,
       if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
         {
           tree intt;
-          if (TREE_TYPE (type0) != TREE_TYPE (type1))
+         if (!vector_types_compatible_elements_p (type0, type1))
             {
               error_at (location, "comparing vectors with different "
                                   "element types");
@@ -10124,7 +10124,7 @@ build_binary_op (location_t location, enum tree_code code,
       if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
         {
           tree intt;
-          if (TREE_TYPE (type0) != TREE_TYPE (type1))
+         if (!vector_types_compatible_elements_p (type0, type1))
             {
               error_at (location, "comparing vectors with different "
                                   "element types");
@@ -10230,8 +10230,7 @@ build_binary_op (location_t location, enum tree_code code,
 
   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))))
+         || !vector_types_compatible_elements_p (type0, type1)))
     {
       binary_op_error (location, code, type0, type1);
       return error_mark_node;
index be8258dcf3ec1fe685663d369601d99148bd11bf..af230f5704b922d8a1f4a3b285b27367cc303c02 100644 (file)
@@ -1,3 +1,7 @@
+2013-09-08  Joern Rennecke  <joern.rennecke@embecosm.com>
+
+       * typeck.c (cp_build_binary_op): Use vector_types_compatible_elements_p.
+
 2013-09-04  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/24926
index b4abbc56d5e23fcf0be6c553c187b6e050cb8c7a..6c48f242dd762eddd5ac80c3b794bed7d482be45 100644 (file)
@@ -4554,7 +4554,8 @@ cp_build_binary_op (location_t location,
        vector_compare:
          tree intt;
          if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
-                                                         TREE_TYPE (type1)))
+                                                         TREE_TYPE (type1))
+             && !vector_types_compatible_elements_p (type0, type1))
            {
              if (complain & tf_error)
                {
@@ -4670,8 +4671,7 @@ cp_build_binary_op (location_t location,
       if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
        {
          if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
-             || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
-                                                       TREE_TYPE (type1)))
+             || !vector_types_compatible_elements_p (type0, type1))
            {
              if (complain & tf_error)
                binary_op_error (location, code, type0, type1);
index a9f6313f15aac6269ac7c23212401242ddc7053b..da1e8a936fdc321f1c8fbba4a8e302d6c9609bec 100644 (file)
@@ -1,3 +1,7 @@
+2013-09-08  Joern Rennecke  <joern.rennecke@embecosm.com>
+
+       * c-c++-common/opaque-vector.c: New test.
+
 2013-09-08  Tom de Vries  <tom@codesourcery.com>
 
        PR c++/58282
diff --git a/gcc/testsuite/c-c++-common/opaque-vector.c b/gcc/testsuite/c-c++-common/opaque-vector.c
new file mode 100644 (file)
index 0000000..cad266e
--- /dev/null
@@ -0,0 +1,22 @@
+#define B_TEST(TYPE) { TYPE v __attribute__((vector_size(16))); (void)((v < v) < v); }
+#ifdef __cplusplus
+#define T_TEST(TYPE) { TYPE s; TYPE v __attribute__((vector_size(16))); __typeof((v<v)[0]) iv __attribute__((vector_size(16))); (void)((iv ? s : s) < v); }
+#else
+#define T_TEST(TYPE)
+#endif
+#define T(TYPE) B_TEST(TYPE) T_TEST(TYPE)
+
+void f ()
+{
+  T(short)
+  T(int)
+  T(long)
+  T(long long)
+
+  T_TEST(float)
+  T_TEST(double)
+  /* Avoid trouble with non-power-of-two sizes.  */
+#if !defined(__i386__) && !defined(__x86_64__) && !defined(__m68k__) && !defined(__ia64__)
+  T_TEST(long double)
+#endif
+}