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

Re: New-ish warning in refs.c with GCC (at least 11.2) under -O3

From
Taylor Blau <me@ttaylorr.com>
Date
Nov 16, 2021, 20:29 UTC
Message-ID
<YZQUxkYI3TES3vDo@nand.local>
In-Reply-To
<YZLhrSoTzrC7wcQo@coredump.intra.peff.net>
On Mon, Nov 15, 2021 at 05:39:41PM -0500, Jeff King wrote:
> So something like the patch at the end of this email works (compiles
> with -O3 and passes the tests), but I think it is just making things
> more confusing.

I can absolutely understand and am sympathetic to the reasons that your patch would be making things more brittle. In some sense, it makes spots like these a little easier to read:

> -			&update->new_oid, &update->old_oid,
> +			update->flags & REF_HAVE_NEW ? &update->new_oid : NULL,
> +			update->flags & REF_HAVE_OLD ? &update->old_oid : NULL,

But I think forcing that burden on every caller is what makes the overall approach worse.

So it's too bad that we even have this problem in the first place, since GCC's warning is clearly a false positive. But I would be OK with the bandaid you propose here:

Show 9 quoted lines
> I think an assertion similar to what you have above is a better bet,
> but perhaps written more simply as:
>
>   if (flags & REF_HAVE_NEW) {
> 	/* silence gcc 11's over-eager compile-time analysis */
> 	if (!new_oid)
> 		BUG("REF_HAVE_NEW set without passing new_oid");
> 	oidcpy(&update->new_oid, new_oid);
>   }

Thanks, Taylor

Previous: Jeff KingNext: Jeff King
Message 3 of 6 in “New-ish warning in refs.c with GCC (at least 11.2) under -O3”
  1. Ævar Arnfjörð BjarmasonNov 15, 2021
  2. Jeff KingNov 15, 2021
  3. Taylor BlauNov 16, 2021
  4. Jeff KingNov 16, 2021
  5. Junio C HamanoNov 18, 2021
  6. refs: work around gcc-11 warning with REF_HAVE_NEWJeff King, Nov 19, 2021

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.