aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2016-01-27 19:13:42 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2016-01-27 19:13:42 +0000
commitfa74a4bca84aabe0a1500e4fe5359895c1f07e55 (patch)
tree89e14ac50918a33bab845eb73ca1f83e8ad5f26c /gcc/c
parent0afff540e652c77b409ce094f64cc2b033495785 (diff)
downloadgcc-fa74a4bca84aabe0a1500e4fe5359895c1f07e55.zip
gcc-fa74a4bca84aabe0a1500e4fe5359895c1f07e55.tar.gz
gcc-fa74a4bca84aabe0a1500e4fe5359895c1f07e55.tar.bz2
re PR c/68062 (ICE when comparing vectors)
PR c/68062 * c-typeck.c (build_binary_op) [EQ_EXPR, GE_EXPR]: Promote operand to unsigned, if needed. Add -Wsign-compare warning. * typeck.c (cp_build_binary_op): Promote operand to unsigned, if needed. Add -Wsign-compare warning. * c-c++-common/vector-compare-4.c: New test. From-SVN: r232894
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c28
2 files changed, 34 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 7d6250e..7999d2a 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2016-01-27 Marek Polacek <polacek@redhat.com>
+
+ PR c/68062
+ * c-typeck.c (build_binary_op) [EQ_EXPR, GE_EXPR]: Promote operand
+ to unsigned, if needed. Add -Wsign-compare warning.
+
2016-01-26 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/69483
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index d602e33..65925cb 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -11048,6 +11048,20 @@ build_binary_op (location_t location, enum tree_code code,
return error_mark_node;
}
+ /* It's not precisely specified how the usual arithmetic
+ conversions apply to the vector types. Here, we use
+ the unsigned type if one of the operands is signed and
+ the other one is unsigned. */
+ if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
+ {
+ if (!TYPE_UNSIGNED (type0))
+ op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
+ else
+ op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
+ warning_at (location, OPT_Wsign_compare, "comparison between "
+ "types %qT and %qT", type0, type1);
+ }
+
/* Always construct signed integer vector type. */
intt = c_common_type_for_size (GET_MODE_BITSIZE
(TYPE_MODE (TREE_TYPE (type0))), 0);
@@ -11201,6 +11215,20 @@ build_binary_op (location_t location, enum tree_code code,
return error_mark_node;
}
+ /* It's not precisely specified how the usual arithmetic
+ conversions apply to the vector types. Here, we use
+ the unsigned type if one of the operands is signed and
+ the other one is unsigned. */
+ if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
+ {
+ if (!TYPE_UNSIGNED (type0))
+ op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
+ else
+ op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
+ warning_at (location, OPT_Wsign_compare, "comparison between "
+ "types %qT and %qT", type0, type1);
+ }
+
/* Always construct signed integer vector type. */
intt = c_common_type_for_size (GET_MODE_BITSIZE
(TYPE_MODE (TREE_TYPE (type0))), 0);