aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoern Rennecke <joern.rennecke@embecosm.com>2013-09-08 06:16:24 +0000
committerJoern Rennecke <amylaar@gcc.gnu.org>2013-09-08 07:16:24 +0100
commit0af94e6f263316ba608487859827f87696bbf377 (patch)
tree0f2eee7eebbfbdf1341ac9855aa139be01e1a520
parentdde03143093de0c0fff6f424dd0676ab5d005bbb (diff)
downloadgcc-0af94e6f263316ba608487859827f87696bbf377.zip
gcc-0af94e6f263316ba608487859827f87696bbf377.tar.gz
gcc-0af94e6f263316ba608487859827f87696bbf377.tar.bz2
c-common.c (same_scalar_type_ignoring_signedness): Delete.
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
-rw-r--r--gcc/c-family/ChangeLog8
-rw-r--r--gcc/c-family/c-common.c52
-rw-r--r--gcc/c-family/c-common.h2
-rw-r--r--gcc/c/ChangeLog4
-rw-r--r--gcc/c/c-typeck.c7
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/typeck.c6
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/c-c++-common/opaque-vector.c22
9 files changed, 97 insertions, 12 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 2a0c406..95babfa 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -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
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 5d1a1c6..62aa9fc 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -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
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index cc09dbc..722ba6e 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -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);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 3401228..1b4b297 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -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.
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index f29ca04..e52533e 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -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;
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index be8258d..af230f57 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b4abbc5..6c48f24 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a9f6313..da1e8a93 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..cad266e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/opaque-vector.c
@@ -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
+}