aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-10-06 09:11:25 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2017-10-06 09:11:25 +0200
commit4e34b338f703d72e1d4a90116e9d2c6aa0a3d5d8 (patch)
tree1edd646c5ff05278d73442bec96be0300188aeaf /gcc/c-family
parentbd8d431f44377efe110b02163d693e60421acdeb (diff)
downloadgcc-4e34b338f703d72e1d4a90116e9d2c6aa0a3d5d8.zip
gcc-4e34b338f703d72e1d4a90116e9d2c6aa0a3d5d8.tar.gz
gcc-4e34b338f703d72e1d4a90116e9d2c6aa0a3d5d8.tar.bz2
re PR c/82437 (false-positive -Wtautological-compare warning with -std=gnu89)
PR c/82437 * c-warn.c (warn_tautological_bitwise_comparison): Instead of using to_widest use wide_int with the larger of the two precisions. * c-c++-common/Wtautological-compare-6.c: New test. From-SVN: r253476
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-warn.c18
2 files changed, 19 insertions, 5 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 639fd22..f70b6f8 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-06 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/82437
+ * c-warn.c (warn_tautological_bitwise_comparison): Instead of
+ using to_widest use wide_int with the larger of the two precisions.
+
2017-10-05 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-pretty-print.c (pp_c_parameter_type_list): Print ... for variadic
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index f86de10..2eb4cf5 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -356,16 +356,24 @@ warn_tautological_bitwise_comparison (location_t loc, tree_code code,
return;
/* Note that the two operands are from before the usual integer
- conversions, so their types might not be the same. */
- widest_int res;
+ conversions, so their types might not be the same.
+ Use the larger of the two precisions and ignore bits outside
+ of that. */
+ int prec = MAX (TYPE_PRECISION (TREE_TYPE (cst)),
+ TYPE_PRECISION (TREE_TYPE (bitopcst)));
+
+ wide_int bitopcstw = wide_int::from (bitopcst, prec, UNSIGNED);
+ wide_int cstw = wide_int::from (cst, prec, UNSIGNED);
+
+ wide_int res;
if (TREE_CODE (bitop) == BIT_AND_EXPR)
- res = wi::to_widest (bitopcst) & wi::to_widest (cst);
+ res = bitopcstw & cstw;
else
- res = wi::to_widest (bitopcst) | wi::to_widest (cst);
+ res = bitopcstw | cstw;
/* For BIT_AND only warn if (CST2 & CST1) != CST1, and
for BIT_OR only if (CST2 | CST1) != CST1. */
- if (res == wi::to_widest (cst))
+ if (res == cstw)
return;
if (code == EQ_EXPR)