This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] [C] Warn when calculating abs(unsigned_value)


On 08/16/2018 10:49 AM, Joseph Myers wrote:
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.

Right.  The warning would need to avoid triggering for arguments
in an unknown range, or in a range that straddles the boundary
between positive and negative values.

But the lack of a distinction between implicit and explicit casts
int the middle-end is a problem, not just here but in other contexts.
Maybe NOP_EXPR could be extended to capture it.  There should be
an unused bit there somewhere.  I suspect this would be far more
work than could be justified for a single warning, but it may be
an idea for a more general design enhancement.

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]