From 73437615120de05275f9af5974f7ee261db9ba61 Mon Sep 17 00:00:00 2001 From: amylaar Date: Sun, 8 Sep 2013 06:16:24 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202364 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c-family/ChangeLog | 8 +++++ gcc/c-family/c-common.c | 52 +++++++++++++++++++++++++++--- gcc/c-family/c-common.h | 2 +- gcc/c/ChangeLog | 4 +++ gcc/c/c-typeck.c | 7 ++-- gcc/cp/ChangeLog | 4 +++ gcc/cp/typeck.c | 6 ++-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/c-c++-common/opaque-vector.c | 22 +++++++++++++ 9 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/opaque-vector.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 2a0c4061198..95babfa743f 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2013-09-08 Joern Rennecke + + * 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 * 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 5d1a1c6c2ce..62aa9fcec2b 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 cc09dbc008f..722ba6e5c15 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 3401228c039..1b4b2977294 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2013-09-08 Joern Rennecke + + * c-typeck.c (build_binary_op): Use vector_types_compatible_elements_p. + 2013-09-03 Gabriel Dos Reis * c-objc-common.c (c_tree_printer): Tidy. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index f29ca049649..e52533ecd6d 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 be8258dcf3e..af230f5704b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2013-09-08 Joern Rennecke + + * typeck.c (cp_build_binary_op): Use vector_types_compatible_elements_p. + 2013-09-04 Paolo Carlini PR c++/24926 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index b4abbc56d5e..6c48f242dd7 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 a9f6313f15a..da1e8a936fd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-09-08 Joern Rennecke + + * c-c++-common/opaque-vector.c: New test. + 2013-09-08 Tom de Vries 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 00000000000..cad266e893b --- /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