diff options
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-warn.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Wtautological-compare-6.c | 11 |
4 files changed, 35 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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f01325a..1021c6a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-10-06 Jakub Jelinek <jakub@redhat.com> + + PR c/82437 + * c-c++-common/Wtautological-compare-6.c: New test. + 2017-10-06 Richard Biener <rguenther@suse.de> * gcc.dg/graphite/id-15.c: No longer expect a code generation error. diff --git a/gcc/testsuite/c-c++-common/Wtautological-compare-6.c b/gcc/testsuite/c-c++-common/Wtautological-compare-6.c new file mode 100644 index 0000000..fcdca72 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wtautological-compare-6.c @@ -0,0 +1,11 @@ +/* PR c/82437 */ +/* { dg-do compile { target int32plus } } */ +/* { dg-options "-Wtautological-compare" } */ + +int +foo (unsigned int x) +{ + if ((x & -1879048192) != -1879048192) /* { dg-bogus "bitwise comparison always evaluates to" } */ + return 0; + return 1; +} |