+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
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)
+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.
--- /dev/null
+/* 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;
+}