https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77743

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
You're right, I missed that the warning is issued even at -O1 on x86_64 as
well.  The false positive at -O1 is due to get_range_info returning the range
of [0, UINT_MAX].  I don't think there is anything the gimple-ssa-sprintf pass
can do to overcome this limitation.  My understanding is that the new VRP pass
that's being developed will provide more accurate range information but I don't
know if it will necessarily guarantee the same range irrespective of
optimization levels.

My recommendation in cases like this where the value of the directive's
argument is constrained to the range of a type with a smaller precision is to
use the conversion specifier appropriate for that type.  I.e., change the code
to:

  sprintf (buf, "\\%03hho", (unsigned int) c & 0xff);

Alternatively, using the warning with -O2 and not at lower levels should
resolve more (though not all) of these false positives.

Since the accuracy of range information is unavoidably limited I'll go ahead
and resolve this bug as won't fix.  If you feel that this class of problems
should be handled differently (or if you know of a fix) please reopen the bug.

Reply via email to