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

Re: [PATCH] Fix -Wmaybe-uninitialized warnings under -O0

From
Jeff King <peff@peff.net>
Date
Apr 3, 2020, 14:38 UTC
Message-ID
<20200403143844.GB639586@coredump.intra.peff.net>
In-Reply-To
<20200403140447.GA639586@coredump.intra.peff.net>
On Fri, Apr 03, 2020 at 10:04:47AM -0400, Jeff King wrote:
> Ah, OK, I can reproduce easily with -Og (up through gcc-10). Most of
> them don't trigger with -O1; just the one in ref-filter.c.

I guess I should have been more clear since the -O1 and -Og locations are different. -O1 complains in filter_refs().

By the way, that function's handling of filter->kind seems very sketchy to me. It does:

  int ret = 0;
  if (!filter->kind)
                die("filter_refs: invalid type");
  else {
          /*
           * For common cases where we need only branches or remotes or tags,
           * we only iterate through those refs. If a mix of refs is needed,
           * we iterate over all refs and filter out required refs with the help
           * of filter_ref_kind().
           */
          if (filter->kind == FILTER_REFS_BRANCHES)
                  ret = for_each_fullref_in("refs/heads/", ...);
          else if (filter->kind == FILTER_REFS_REMOTES)
                  ret = for_each_fullref_in("refs/remotes/", ...);
          else if (filter->kind == FILTER_REFS_TAGS)
                  ret = for_each_fullref_in("refs/tags/", ...);
          else if (filter->kind & FILTER_REFS_ALL)
                  ret = for_each_fullref_in_pattern(filter, ...);
          if (!ret && (filter->kind & FILTER_REFS_DETACHED_HEAD))
                  head_ref(...);
  }

So filter->kind is sometimes treated like a bitfield and sometimes not. I can set it to (ALL & DETACHED_HEAD) to get something useful, but not (BRANCHES & HEAD). The up-front check tries to complain if you didn't ask for anything, but there are other flags like INCLUDE_BROKEN that would cause "!filter->kind" to be false, but still not produce any output.

And shouldn't we be checking the return value of head_ref() like the others?

All of this is outside the scope of our current discussion, and untangling it might be messy (because it could touch the callers). I just wanted to document my findings for now. :)

-Peff
Previous: Jeff KingNext: Denton Liu
Message 5 of 31 in “Fix -Wmaybe-uninitialized warnings under -O0”
  1. Fix -Wmaybe-uninitialized warnings under -O0Denton Liu, Apr 1, 2020
  2. Jeff KingApr 1, 2020
  3. Denton LiuApr 1, 2020
  4. Jeff KingApr 3, 2020
  5. Jeff KingApr 3, 2020
  6. Denton LiuApr 4, 2020
  7. Jeff KingApr 4, 2020
  8. trace2: refactor to avoid gcc warning under -O3Ævar Arnfjörð Bjarmason, May 5, 2021
  9. Junio C HamanoMay 5, 2021
  10. Jeff KingMay 5, 2021
  11. Johannes SchindelinMay 5, 2021
  12. Junio C HamanoMay 6, 2021
  13. Johannes SchindelinMay 6, 2021
  14. Junio C HamanoMay 6, 2021
  15. Johannes SchindelinMay 11, 2021
  16. Jeff KingMay 11, 2021
  17. Junio C HamanoMay 11, 2021
  18. Jeff KingMay 11, 2021
  19. Junio C HamanoMay 11, 2021
  20. Junio C HamanoMay 11, 2021
  21. trace2: refactor to avoid gcc warning under -O3Ævar Arnfjörð Bjarmason, May 11, 2021
  22. Jeff HostetlerMay 11, 2021
  23. Jeff KingMay 11, 2021
  24. Jeff KingMay 11, 2021
  25. Junio C HamanoMay 11, 2021
  26. Junio C HamanoMay 20, 2021
  27. trace2: refactor to avoid gcc warning under -O3Ævar Arnfjörð Bjarmason, May 20, 2021
  28. Jeff KingMay 20, 2021
  29. Junio C HamanoMay 20, 2021
  30. Jeff KingMay 21, 2021
  31. Denton LiuApr 1, 2020

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.