Commit 4e34b338 by Jakub Jelinek Committed by Jakub Jelinek

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
parent bd8d431f
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> 2017-10-05 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-pretty-print.c (pp_c_parameter_type_list): Print ... for variadic * c-pretty-print.c (pp_c_parameter_type_list): Print ... for variadic
......
...@@ -356,16 +356,24 @@ warn_tautological_bitwise_comparison (location_t loc, tree_code code, ...@@ -356,16 +356,24 @@ warn_tautological_bitwise_comparison (location_t loc, tree_code code,
return; return;
/* Note that the two operands are from before the usual integer /* Note that the two operands are from before the usual integer
conversions, so their types might not be the same. */ conversions, so their types might not be the same.
widest_int res; 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) if (TREE_CODE (bitop) == BIT_AND_EXPR)
res = wi::to_widest (bitopcst) & wi::to_widest (cst); res = bitopcstw & cstw;
else 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_AND only warn if (CST2 & CST1) != CST1, and
for BIT_OR only if (CST2 | CST1) != CST1. */ for BIT_OR only if (CST2 | CST1) != CST1. */
if (res == wi::to_widest (cst)) if (res == cstw)
return; return;
if (code == EQ_EXPR) 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> 2017-10-06 Richard Biener <rguenther@suse.de>
* gcc.dg/graphite/id-15.c: No longer expect a code generation error. * gcc.dg/graphite/id-15.c: No longer expect a code generation error.
......
/* 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment