[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: strange warnings
- From: Mike Pall <mikelu-1106@...>
- Date: Thu, 9 Jun 2011 19:13:44 +0200
Roberto Ierusalimschy wrote:
> > Roberto Ierusalimschy wrote:
> > > When compiling Lua 5.1.4 with gcc (version 4.4.3) with option
> > > -Wstrict-overflow=2, I get two warnings that I cannot understand:
> > >
> > > lvm.c: In function ‘luaV_concat’:
> > > lvm.c:300: warning: assuming signed overflow does not occur when simplifying conditional to constant
> >
> > GCC deduces that n >= 1 from scalar evolution analysis earlier in
> > line 293. SCEV assumes that n++ does not overflow. You get the
> > warning in line 300 because the loop entry condition has been
> > eliminated based on SCEV and VRP (value range propagation).
>
> I thought about that, but it seems very strange (I would call it a bug)
> to give a warning about code that the compiler itself created. The
> written code (the only one of concern to warnings) does not have a
> separated loop entry condition; the only condition it does have is not
> constant.
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. [...]
--Mike