[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: strange warnings
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 9 Jun 2011 14:54:51 -0300
> Ahem. You're complaining that this warning is doing what it's
> supposed to do! Please read the GCC manual page (emphasis mine):
>
> -Wstrict-overflow=n
>
> [...] It warns about cases where the compiler optimizes based on
> the assumption that signed overflow does not occur. Note that
> it does not warn about all cases where the code might overflow:
> IT ONLY WARNS ABOUT CASES WHERE THE COMPILER IMPLEMENTS SOME
> OPTIMIZATION. Thus this warning depends on the optimization level.
>
> An optimization which assumes that signed overflow does not
> occur is perfectly safe if the values of the variables involved
> are such that overflow never does, in fact, occur. THEREFORE
> THIS WARNING CAN EASILY GIVE A FALSE POSITIVE: a warning about
> code which is not actually a problem. [...]
I did read the documentation. It did not mention that it could warn
about code that I did not write. So, I assumed it did refer to code
that I wrote.
The problem is not that it is giving a false positive. The problem is
that it is giving a true positive, but about code that does not exist
in the source. In the case of lua.c, it actually gives *five* times the
same warning:
lua.c:436: warning: assuming signed overflow does not occur when simplifying conditional to constant
I am sure there are not five conditionals there (but it created five
paths where the condition is constant).
For me (after reading the documentation!) what this warning is supposed
to do is something like the following (real) example:
if (i < 0) {
i = -i; /* must be a positive value */
if (i < 0) i = 0; /* handle INT_MIN */
}
Here, the compiler implements some optimization based on the fact that
overflow does not occur, and so the test that I wrote (the second
(i < 0)) is indeed constant (and therefore removed).
-- Roberto