Re: Question about -Wstrict-overflow=2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/6/21 12:03 PM, Alexander Motzkau via Gcc-help wrote:
> Andrew Haley wrote:
>> The compiler is telling you that it's assuming that expbuf + 120
>> does not wrap around. There's nothing really mysterious about it.
> 
> But should that warning only occur on -Wstrict-overflow=3 or higher?
> Why does it occur on -Wstrict-overflow=2?

-Wstrict-overflow=2 triggers when GCC encounters expressions that
reduce to a constant, where that evaluation depends on overflow not
occuring. In this case the expression is

   expbuf + 120 > get_buf()

This exact phrase doesn't occur in your program, but GCC generates it
while optimizing.

> I usually compile my software with -Werror (so that warnings won't be
> ignored anymore) and so this information from the compiler broke the build
> when going from GCC 8 to GCC 9. It seems -Wstrict-overflow=2 there is not
> fit to be used with -Werror anymore. Am I correct?

I doubt that it ever was. -Wstrict-overflow=2 is informative, for the
programmer. It doesn't suggest that anything is questionable  about the
program, and in this case it's difficult or impossible to avoid.

Re upgrading: over time, GCC gets better and better at diagnosing and
providing information. This inevitably means that programmers using
-Werror with high levels of warnings have to change their programs
when a new GCC is used.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux