* [Bug?] compiler warning with gcc >= 4.2
@ 2007-07-03 12:58 Frank Lichtenheld
2007-07-03 14:18 ` Nicolas Pitre
0 siblings, 1 reply; 3+ messages in thread
From: Frank Lichtenheld @ 2007-07-03 12:58 UTC (permalink / raw)
To: Git Mailing List
Hi,
while testing for an (probably) unrelated miscompilation bug,
I got the following warning while compiling git:
gcc-4.2 -o sha1_file.o -c -g -O2 -Wall -DSHA1_HEADER='<openssl/sha.h>'
-DETC_GITCONFIG='"/home/djpig/etc/gitconfig"' -DNO_STRLCPY sha1_file.c
sha1_file.c: In function ‘check_packed_git_idx’:
sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
This comes from the new -Wstrict-overflow which warns about the fact
that with -fstrict-overflow, which is activated by default with -O2,
the if clause referenced in the warning will be optimised away.
So I would be interested to know
a) if the compiler optimising this check away (which seems to be a check
about whether signed overflow can occour) can lead to unwanted results
b) if not a), if it would make sense trying to suppress that warning, so
that other people don't end up wondering the same as me
The used compiler was:
$ gcc-4.2 -v
Using built-in specs.
Target: hppa-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr
--disable-libssp --disable-werror --enable-checking=release
--build=hppa-linux-gnu --host=hppa-linux-gnu
--target=hppa-linux-gnuThread model: posix
gcc version 4.2.1 20070627 (prerelease) (Debian 4.2-20070627-1)
Gruesse,
--
Frank Lichtenheld <frank@lichtenheld.de>
www: http://www.djpig.de/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Bug?] compiler warning with gcc >= 4.2
2007-07-03 12:58 [Bug?] compiler warning with gcc >= 4.2 Frank Lichtenheld
@ 2007-07-03 14:18 ` Nicolas Pitre
2007-07-06 8:55 ` Jan Hudec
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Pitre @ 2007-07-03 14:18 UTC (permalink / raw)
To: Frank Lichtenheld; +Cc: Git Mailing List
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1850 bytes --]
On Tue, 3 Jul 2007, Frank Lichtenheld wrote:
> Hi,
>
> while testing for an (probably) unrelated miscompilation bug,
> I got the following warning while compiling git:
>
> gcc-4.2 -o sha1_file.o -c -g -O2 -Wall -DSHA1_HEADER='<openssl/sha.h>'
> -DETC_GITCONFIG='"/home/djpig/etc/gitconfig"' -DNO_STRLCPY sha1_file.c
> sha1_file.c: In function ‘check_packed_git_idx’:
> sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
> sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
>
> This comes from the new -Wstrict-overflow which warns about the fact
> that with -fstrict-overflow, which is activated by default with -O2,
> the if clause referenced in the warning will be optimised away.
>
> So I would be interested to know
> a) if the compiler optimising this check away (which seems to be a check
> about whether signed overflow can occour) can lead to unwanted results
Of course it can if the compiler blindly optimizes the test away.
In this particular case, the answer can be determined at compile time
though, since all values to perform the test are constants. So in this
case the warning is rather obnoxious.
However it would be completely wrong if the compiler optimized away the
if from index-pack.c on line 104, or from builtin-pack-objects.c on line
579. Even warning about it without actually optimizing it away would be
bad in those cases.
> b) if not a), if it would make sense trying to suppress that warning, so
> that other people don't end up wondering the same as me
I really wonder what's the point for gcc to warn about such things.
Sure the warning should go away, but not by compromizing the test that
we need performed on the actual definition of off_t.
Nicolas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Bug?] compiler warning with gcc >= 4.2
2007-07-03 14:18 ` Nicolas Pitre
@ 2007-07-06 8:55 ` Jan Hudec
0 siblings, 0 replies; 3+ messages in thread
From: Jan Hudec @ 2007-07-06 8:55 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: Frank Lichtenheld, Git Mailing List
[-- Attachment #1: Type: text/plain, Size: 2659 bytes --]
On Tue, Jul 03, 2007 at 10:18:52 -0400, Nicolas Pitre wrote:
> On Tue, 3 Jul 2007, Frank Lichtenheld wrote:
>
> > Hi,
> >
> > while testing for an (probably) unrelated miscompilation bug,
> > I got the following warning while compiling git:
> >
> > gcc-4.2 -o sha1_file.o -c -g -O2 -Wall -DSHA1_HEADER='<openssl/sha.h>'
> > -DETC_GITCONFIG='"/home/djpig/etc/gitconfig"' -DNO_STRLCPY sha1_file.c
> > sha1_file.c: In function ‘check_packed_git_idx’:
> > sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
> > sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
> >
> > This comes from the new -Wstrict-overflow which warns about the fact
> > that with -fstrict-overflow, which is activated by default with -O2,
> > the if clause referenced in the warning will be optimised away.
> >
> > So I would be interested to know
> > a) if the compiler optimising this check away (which seems to be a check
> > about whether signed overflow can occour) can lead to unwanted results
>
> Of course it can if the compiler blindly optimizes the test away.
>
> In this particular case, the answer can be determined at compile time
> though, since all values to perform the test are constants. So in this
> case the warning is rather obnoxious.
>
> However it would be completely wrong if the compiler optimized away the
> if from index-pack.c on line 104, or from builtin-pack-objects.c on line
> 579. Even warning about it without actually optimizing it away would be
> bad in those cases.
The compiler *will* optimize it away according to the manual
(http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Optimize-Options.html#index-fstrict_002doverflow-551).
Reasoning behind that is, that C standard does not define what will happen on
signed overflow and therefore the code should not depend on it. Gcc 4.2 has
an option to specify that signed overflow always wraps -- -fwrapv, in which
case the compiler will compute the result as intended (and should not produce
the warning).
> > b) if not a), if it would make sense trying to suppress that warning, so
> > that other people don't end up wondering the same as me
>
> I really wonder what's the point for gcc to warn about such things.
> Sure the warning should go away, but not by compromizing the test that
> we need performed on the actual definition of off_t.
Yes, there is. The expression is undefined according to the C specification,
(or at least GCC manual claims it).
--
Jan 'Bulb' Hudec <bulb@ucw.cz>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-07-06 8:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-03 12:58 [Bug?] compiler warning with gcc >= 4.2 Frank Lichtenheld
2007-07-03 14:18 ` Nicolas Pitre
2007-07-06 8:55 ` Jan Hudec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).