Current-Users archive

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

Re: -fstrict-overflow and -Wstrict-overflow

On Sat, 13 Oct 2012, David Holland wrote:
> Do you have an example where gcc does the wrong thing with
> -Wstrict-overflow?  (The example in your message, which I am not
> quoting here, showed gcc doing the right thing: that is, drawing
> attention to a case where the program invoked undefined behaviour.)

fairly simple one: games/backgammon/backgammon/move.c, at line 164.

There, mvlim is external, so the compiler can't prove that overflow
is impossible, even though humans can prove it.

At least one of the warnings from src/lib/libm/src/e_jn.c also seems bogus: gcc warns about line 75, but I can't see a way for the n==0 test on line 75 to give surprising results as a consequence of integer overflow. (Even if the n=-n assignment on line 71 overflows, that doesn't affect the n==0 test on line 75).

So I agree that -Wstrict-overflow (same as -Wstrict-overflow=2) warns about too many cases that will not actually overflow. -Wstrict-overflow=1 (implied by -Wall) seems to be more reasonable.

However, I think that -fstrict-overflow (implied by -O2) is fine; it permits optimisations that may surprise people who forget that signed integer overflow is undefined, but such optimisations are allowed by the language.

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index