{"thread":{"id":"8835","subject":"[Bug?] compiler warning with gcc >= 4.2","startedAt":"2007-07-03T12:58:44Z","lastAt":"2007-07-06T08:55:08Z","messageCount":3,"participants":["Frank Lichtenheld","Nicolas Pitre","Jan Hudec"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"46360","messageId":"20070703125844.GL12721@planck.djpig.de","threadId":"8835","inReplyTo":null,"subject":"[Bug?] compiler warning with gcc >= 4.2","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2007-07-03T12:58:44Z","receivedAt":"2007-07-03T12:58:44Z","isPatch":false,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"Hi,\n\nwhile testing for an (probably) unrelated miscompilation bug,\nI got the following warning while compiling git:\n\ngcc-4.2 -o sha1_file.o -c -g -O2 -Wall  -DSHA1_HEADER='<openssl/sha.h>'\n-DETC_GITCONFIG='\"/home/djpig/etc/gitconfig\"' -DNO_STRLCPY sha1_file.c\nsha1_file.c: In function ‘check_packed_git_idx’:\nsha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false\nsha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false\n\nThis comes from the new -Wstrict-overflow which warns about the fact\nthat with -fstrict-overflow, which is activated by default with -O2,\nthe if clause referenced in the warning will be optimised away.\n\nSo I would be interested to know\na) if the compiler optimising this check away (which seems to be a check\n   about whether signed overflow can occour) can lead to unwanted results\nb) if not a), if it would make sense trying to suppress that warning, so\n   that other people don't end up wondering the same as me\n\nThe used compiler was:\n$ gcc-4.2 -v\nUsing built-in specs.\nTarget: hppa-linux-gnu\nConfigured with: ../src/configure -v\n--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr\n--enable-shared --with-system-zlib --libexecdir=/usr/lib\n--without-included-gettext --enable-threads=posix --enable-nls\n--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2\n--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr\n--disable-libssp --disable-werror --enable-checking=release\n--build=hppa-linux-gnu --host=hppa-linux-gnu\n--target=hppa-linux-gnuThread model: posix\ngcc version 4.2.1 20070627 (prerelease) (Debian 4.2-20070627-1)\n\nGruesse,\n-- \nFrank Lichtenheld <frank@lichtenheld.de>\nwww: http://www.djpig.de/\n"},{"id":"46369","messageId":"alpine.LFD.0.999.0707030957160.26459@xanadu.home","threadId":"8835","inReplyTo":"20070703125844.GL12721@planck.djpig.de","subject":"Re: [Bug?] compiler warning with gcc >= 4.2","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-07-03T14:18:52Z","receivedAt":"2007-07-03T14:18:52Z","isPatch":false,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Tue, 3 Jul 2007, Frank Lichtenheld wrote:\n\n> Hi,\n> \n> while testing for an (probably) unrelated miscompilation bug,\n> I got the following warning while compiling git:\n> \n> gcc-4.2 -o sha1_file.o -c -g -O2 -Wall  -DSHA1_HEADER='<openssl/sha.h>'\n> -DETC_GITCONFIG='\"/home/djpig/etc/gitconfig\"' -DNO_STRLCPY sha1_file.c\n> sha1_file.c: In function ‘check_packed_git_idx’:\n> sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false\n> sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false\n> \n> This comes from the new -Wstrict-overflow which warns about the fact\n> that with -fstrict-overflow, which is activated by default with -O2,\n> the if clause referenced in the warning will be optimised away.\n> \n> So I would be interested to know\n> a) if the compiler optimising this check away (which seems to be a check\n>    about whether signed overflow can occour) can lead to unwanted results\n\nOf course it can if the compiler blindly optimizes the test away.\n\nIn this particular case, the answer can be determined at compile time \nthough, since all values to perform the test are constants.  So in this \ncase the warning is rather obnoxious.\n\nHowever it would be completely wrong if the compiler optimized away the \nif from index-pack.c on line 104, or from builtin-pack-objects.c on line \n579.  Even warning about it without actually optimizing it away would be \nbad in those cases.\n\n> b) if not a), if it would make sense trying to suppress that warning, so\n>    that other people don't end up wondering the same as me\n\nI really wonder what's the point for gcc to warn about such things.  \nSure the warning should go away, but not by compromizing the test that \nwe need performed on the actual definition of off_t.\n\n\nNicolas\n"},{"id":"46608","messageId":"20070706085508.GC3991@efreet.light.src","threadId":"8835","inReplyTo":"alpine.LFD.0.999.0707030957160.26459@xanadu.home","subject":"Re: [Bug?] compiler warning with gcc >= 4.2","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-07-06T08:55:08Z","receivedAt":"2007-07-06T08:55:08Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Tue, Jul 03, 2007 at 10:18:52 -0400, Nicolas Pitre wrote:\n> On Tue, 3 Jul 2007, Frank Lichtenheld wrote:\n> \n> > Hi,\n> > \n> > while testing for an (probably) unrelated miscompilation bug,\n> > I got the following warning while compiling git:\n> > \n> > gcc-4.2 -o sha1_file.o -c -g -O2 -Wall  -DSHA1_HEADER='<openssl/sha.h>'\n> > -DETC_GITCONFIG='\"/home/djpig/etc/gitconfig\"' -DNO_STRLCPY sha1_file.c\n> > sha1_file.c: In function ‘check_packed_git_idx’:\n> > sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false\n> > sha1_file.c:523: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false\n> > \n> > This comes from the new -Wstrict-overflow which warns about the fact\n> > that with -fstrict-overflow, which is activated by default with -O2,\n> > the if clause referenced in the warning will be optimised away.\n> > \n> > So I would be interested to know\n> > a) if the compiler optimising this check away (which seems to be a check\n> >    about whether signed overflow can occour) can lead to unwanted results\n> \n> Of course it can if the compiler blindly optimizes the test away.\n> \n> In this particular case, the answer can be determined at compile time \n> though, since all values to perform the test are constants.  So in this \n> case the warning is rather obnoxious.\n> \n> However it would be completely wrong if the compiler optimized away the \n> if from index-pack.c on line 104, or from builtin-pack-objects.c on line \n> 579.  Even warning about it without actually optimizing it away would be \n> bad in those cases.\n\nThe compiler *will* optimize it away according to the manual\n(http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Optimize-Options.html#index-fstrict_002doverflow-551).\nReasoning behind that is, that C standard does not define what will happen on\nsigned overflow and therefore the code should not depend on it. Gcc 4.2 has\nan option to specify that signed overflow always wraps -- -fwrapv, in which\ncase the compiler will compute the result as intended (and should not produce\nthe warning).\n\n> > b) if not a), if it would make sense trying to suppress that warning, so\n> >    that other people don't end up wondering the same as me\n> \n> I really wonder what's the point for gcc to warn about such things.  \n> Sure the warning should go away, but not by compromizing the test that \n> we need performed on the actual definition of off_t.\n\nYes, there is. The expression is undefined according to the C specification,\n(or at least GCC manual claims it).\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"}]}