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

Re: [PATCH] http.c: clear the 'finished' member once we are done with it

From
Carlo Arenas <carenas@gmail.com>
Date
May 25, 2022, 02:02 UTC
Message-ID
<CAPUEsph5udmc7pyza0WdhXDFfHSm96Xwt3CnEiPnSDSqY6fOUg@mail.gmail.com>
In-Reply-To
<xmqqo7zmcydv.fsf@gitster.g>

Please, I apologize in advance because I am making statements way above my paygrade and without the relevant foundation (because as I mentioned, I looked at it briefly a while ago, and hadn't been able to get the time to complete my analysis).

I did read all your analysis and while as Aevar pointed out, I might be mistaken, or not making myself clear enough, it is not intentional and if told to do so, will extract myself from this thread until I can do a full analysis.

On Tue, May 24, 2022 at 4:19 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Is such a use of the pointer in the structure a cause for an
> undefined behaviour?

If you make an IMHO overly strict reading of the standard (which it would seem gcc12 implementers might have done) then ANY access to a pointer that might be out of scope is Undefined Behaviour.

gcc doesn't know what happens to the variable after it gets shipped out of this function inside that opaque structure that is passed around between threads in curl, so it MIGHT reasonably assume that:

1) There is a layering violation somewhere and another thread is
modifying that field to point it to a different thread local from the
same function.
2) Once it gets the value back, then it can assume that reading that
pointer might be undefined behaviour because it might be coming from a
different stack frame than ours (after all, any sane developer would
store instead a flag)
3) since the if uses a condition that is UB then it can optimize it out

I can't see any other reason why in the original code, with the if, the warning was still being triggered, but not without it.

BTW while trying to debug gcc to find out if this is a bug or a lost opportunity for optimization of something else, I noticed that it would only trigger in cases where the structure was shipped outside the function through another function, not when it was returned back from it, for example.

I don't even have gcc-12 in the current workstation I am using, but would prepare a machine with it and debug further if you think giving a more complete answer is necessary.

Carlo
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 30 of 38 in “quell a few gcc warnings”
  1. 0/2 quell a few gcc warningsMichael J Gruber, May 6, 2022
  2. 1/2 dir.c: avoid gcc warningMichael J Gruber, May 6, 2022
  3. Junio C HamanoMay 6, 2022
  4. Taylor BlauMay 9, 2022
  5. Carlo Marcelo Arenas BelónMay 7, 2022
  6. 2/2 http.c: avoid gcc warningMichael J Gruber, May 6, 2022
  7. Junio C HamanoMay 6, 2022
  8. http.c: clear the 'finished' member once we are done with itJunio C Hamano, May 6, 2022
  9. Carlo Marcelo Arenas BelónMay 7, 2022
  10. Junio C HamanoMay 7, 2022
  11. Carlo ArenasMay 7, 2022
  12. Johannes SchindelinMay 23, 2022
  13. Junio C HamanoMay 23, 2022
  14. Junio C HamanoMay 23, 2022
  15. Johannes SchindelinMay 23, 2022
  16. Junio C HamanoMay 24, 2022
  17. Daniel StenbergMay 24, 2022
  18. Johannes SchindelinMay 24, 2022
  19. Junio C HamanoMay 24, 2022
  20. Daniel StenbergMay 26, 2022
  21. Johannes SchindelinMay 24, 2022
  22. Junio C HamanoMay 24, 2022
  23. Carlo Marcelo Arenas BelónMay 24, 2022
  24. Ævar Arnfjörð BjarmasonMay 24, 2022
  25. Junio C HamanoMay 24, 2022
  26. Michael J GruberMay 25, 2022
  27. Ævar Arnfjörð BjarmasonMay 25, 2022
  28. Junio C HamanoMay 24, 2022
  29. Junio C HamanoMay 24, 2022
  30. Carlo ArenasMay 25, 2022
  31. Ævar Arnfjörð BjarmasonMay 24, 2022
  32. Junio C HamanoMay 24, 2022
  33. Johannes SchindelinMay 25, 2022
  34. Junio C HamanoMay 25, 2022
  35. Carlo Marcelo Arenas BelónMay 6, 2022
  36. detect-compiler: make detection independent of localeMichael J Gruber, May 9, 2022
  37. Junio C HamanoMay 9, 2022
  38. rsbecker@nexbridge.comMay 9, 2022

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.