git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [Bug?] compiler warning with gcc >= 4.2

From
Nicolas Pitre <nico@cam.org>
Date
Jul 3, 2007, 14:18 UTC
Message-ID
<alpine.LFD.0.999.0707030957160.26459@xanadu.home>
In-Reply-To
<20070703125844.GL12721@planck.djpig.de>
On Tue, 3 Jul 2007, Frank Lichtenheld wrote:
Show 18 quoted lines
> 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
Previous: Frank LichtenheldNext: Jan Hudec
Message 2 of 3 in “[Bug?] compiler warning with gcc >= 4.2”
  1. Frank LichtenheldJul 3, 2007
  2. Nicolas PitreJul 3, 2007
  3. Jan HudecJul 6, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.