[PATCH] [C] Warn when calculating abs(unsigned_value)
Joseph Myers
joseph@codesourcery.com
Thu Aug 16 16:50:00 GMT 2018
On Wed, 15 Aug 2018, Martin Sebor wrote:
> Detecting some of these bugs without too much noise would require
> moving the warning out of the front-end and to some later point
> after VRP has run.
But you need the information about whether the conversion was explicit or
implicit. If someone does
abs ((int) unsigned_var)
it's presumably intentional and should not receive a warning. If they do
abs (unsigned_var)
it's suspect. If they do
abs (long_var)
it's entirely possible they know the long value is within range for int,
but it came from some API that produces long.
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Gcc-patches
mailing list