{"thread":{"id":"61788","subject":"[PATCH] sparse: ignore warning from new glibc headers","startedAt":"2024-07-16T23:17:58Z","lastAt":"2025-04-08T22:35:15Z","messageCount":15,"participants":["Đoàn Trần Công Danh","Junio C Hamano","Ramsay Jones","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"498808","messageId":"a667da3985a0fe943cc0ff6ee8513d731d75a299.1721171853.git.congdanhqx@gmail.com","threadId":"61788","inReplyTo":null,"subject":"[PATCH] sparse: ignore warning from new glibc headers","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2024-07-16T23:17:41Z","receivedAt":"2024-07-16T23:17:58Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"With at least glibc 2.39, glibc provides a function declaration that\nmatches with this POSIX interface:\n\n    int regexec(const regex_t *restrict preg, const char *restrict string,\n           size_t nmatch, regmatch_t pmatch[restrict], int eflags);\n\nsuch prototype requires variable-length-array for `pmatch'.\n\nThus, sparse reports this error:\n\n> ../add-patch.c: note: in included file (through ../git-compat-util.h):\n> /usr/include/regex.h:682:41: error: undefined identifier '__nmatch'\n> /usr/include/regex.h:682:41: error: bad constant expression type\n> /usr/include/regex.h:682:41: error: Variable length array is used.\n\nNote: `__nmatch' is POSIX's nmatch.\n\nThe glibc's intention is informing their users to provides a large\nenough buffer to hold `__nmatch' results and provides diagnosis if\nnecessary.  It's merely a glibc' implementation detail.\n\nHide that usage from sparse by using standard C11's macro:\n__STDC_NO_VLA__\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n Makefile | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Makefile b/Makefile\nindex bc81d3395032a..4b9daca1dcc58 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1381,7 +1381,7 @@ ARFLAGS = rcs\n PTHREAD_CFLAGS =\n \n # For the 'sparse' target\n-SPARSE_FLAGS ?= -std=gnu99\n+SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__\n SP_EXTRA_FLAGS = -Wno-universal-initializer\n \n # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets\n-- \n2.45.2.599.g51c0d632d3b6f\n\n"},{"id":"498841","messageId":"xmqqikx42c42.fsf@gitster.g","threadId":"61788","inReplyTo":"a667da3985a0fe943cc0ff6ee8513d731d75a299.1721171853.git.congdanhqx@gmail.com","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-17T16:54:05Z","receivedAt":"2024-07-17T16:54:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh <congdanhqx@gmail.com> writes:\n\n> With at least glibc 2.39, glibc provides a function declaration that\n> matches with this POSIX interface:\n>\n>     int regexec(const regex_t *restrict preg, const char *restrict string,\n>            size_t nmatch, regmatch_t pmatch[restrict], int eflags);\n>\n> such prototype requires variable-length-array for `pmatch'.\n> ...\n> Thus, sparse reports this error:\n>\n>> ../add-patch.c: note: in included file (through ../git-compat-util.h):\n>> /usr/include/regex.h:682:41: error: undefined identifier '__nmatch'\n>> /usr/include/regex.h:682:41: error: bad constant expression type\n>> /usr/include/regex.h:682:41: error: Variable length array is used.\n\nI get the same with \n\n\t$ sparse --version\n\tv0.6.4-66-g0196afe1\n\nWhat I have locally in /usr/include may be a bit older.  It reads\nlike this:\n\n        extern int regexec (const regex_t *_Restrict_ __preg,\n                            const char *_Restrict_ __String, size_t __nmatch,\n                            regmatch_t __pmatch[_Restrict_arr_\n                                                _REGEX_NELTS (__nmatch)],\n                            int __eflags);\n\nwhere _Restrct_arr_ and _Restrict_ would become an empty string for\nolder compilers, and _REGEX_NELTS(foo) becomes empty when VLA is not\navailable.  I think their intention, when the compiler fully supports\nall the necessary features, is to turn the fourth parameter into\n\n\tregmatch_t __pmatch[restrict __nmatch]\n\nI can see how your patch forces the fourth parameter to become (ISO C99)\n\n\tregmatch_t __pmatch[restrict]\n\nor even plain vanilla\n\n\tregmatch_t __pmatch[]\n\nto erase the mention of __nmatch that is not understood by sparse.\n\n> diff --git a/Makefile b/Makefile\n> index bc81d3395032a..4b9daca1dcc58 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1381,7 +1381,7 @@ ARFLAGS = rcs\n>  PTHREAD_CFLAGS =\n>  \n>  # For the 'sparse' target\n> -SPARSE_FLAGS ?= -std=gnu99\n> +SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__\n>  SP_EXTRA_FLAGS = -Wno-universal-initializer\n>  \n>  # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets\n\nBut it makes me feel a bit dirty to define the macro that only\ncompiler implementations are expected to define (or not)[*1*] to\ncause header files behave the way they would with a compiler without\nVLA.  I dunno.\n\n[Reference]\n\n *1* https://port70.net/~nsz/c/c11/n1570.html#6.10.8p2\n"},{"id":"498848","messageId":"9bdac465-5f43-42de-9cad-e6c43a5a53cc@ramsayjones.plus.com","threadId":"61788","inReplyTo":"xmqqikx42c42.fsf@gitster.g","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2024-07-17T18:40:35Z","receivedAt":"2024-07-17T18:40:39Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 17/07/2024 17:54, Junio C Hamano wrote:\n> Đoàn Trần Công Danh <congdanhqx@gmail.com> writes:\n> \n>> With at least glibc 2.39, glibc provides a function declaration that\n>> matches with this POSIX interface:\n>>\n>>     int regexec(const regex_t *restrict preg, const char *restrict string,\n>>            size_t nmatch, regmatch_t pmatch[restrict], int eflags);\n>>\n>> such prototype requires variable-length-array for `pmatch'.\n>> ...\n>> Thus, sparse reports this error:\n>>\n>>> ../add-patch.c: note: in included file (through ../git-compat-util.h):\n>>> /usr/include/regex.h:682:41: error: undefined identifier '__nmatch'\n>>> /usr/include/regex.h:682:41: error: bad constant expression type\n>>> /usr/include/regex.h:682:41: error: Variable length array is used.\n\nYes, I noted this about 2 years ago! If memory serves, it was when the\nlibc6-dev package went from v2.31 to 2.35 (well 2.31-0ubuntu9.9).\n\nAs I said at the time, this only affected glibc platforms (so not newlib\non cygwin for example) of a certain vintage, so I just added\n\n  SPARSE_FLAGS += -D__STDC_NO_VLA__\n\nto my config.mak file.\n\n> I get the same with \n> \n> \t$ sparse --version\n> \tv0.6.4-66-g0196afe1\n> \n\nI mentioned this problem to Luc on the sparse mailing list[1] and\nhe produced a patch which 'fixed' the problem in one way, but\ncaused a different problem[2]. Namely, because git passes -Wvla\nto gcc, it now issues the 'used vla' warnings, which gcc does\nnot because of some '# pragma GCC diagnostic ignored \"-Wvla\"' which\nsparse does not honor! :(\n\nSo, his patch was not applied in the end.\n\nATB,\nRamsay Jones\n\nThe sparse mailing list archive can be found at:\n\n   https://lore.kernel.org/linux-sparse\n\nThe messages below were from December 2023 (approx. 20/12/2023)\n\n[1] Message-ID: <6f853a6b-9ac3-4bfd-a968-89d43fbcce2a@ramsayjones.plus.com>\n[2] Message-ID: <24cb6194-d04d-4c80-bd95-4f7356667884@ramsayjones.plus.com>\n"},{"id":"498849","messageId":"xmqqr0br26ok.fsf@gitster.g","threadId":"61788","inReplyTo":"9bdac465-5f43-42de-9cad-e6c43a5a53cc@ramsayjones.plus.com","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-17T18:51:23Z","receivedAt":"2024-07-17T18:51:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsayjones.plus.com> writes:\n\n> On 17/07/2024 17:54, Junio C Hamano wrote:\n>> Đoàn Trần Công Danh <congdanhqx@gmail.com> writes:\n>> \n>>> With at least glibc 2.39, glibc provides a function declaration that\n>>> matches with this POSIX interface:\n>>>\n>>>     int regexec(const regex_t *restrict preg, const char *restrict string,\n>>>            size_t nmatch, regmatch_t pmatch[restrict], int eflags);\n>>>\n>>> such prototype requires variable-length-array for `pmatch'.\n>>> ...\n>>> Thus, sparse reports this error:\n>>>\n>>>> ../add-patch.c: note: in included file (through ../git-compat-util.h):\n>>>> /usr/include/regex.h:682:41: error: undefined identifier '__nmatch'\n>>>> /usr/include/regex.h:682:41: error: bad constant expression type\n>>>> /usr/include/regex.h:682:41: error: Variable length array is used.\n>\n> Yes, I noted this about 2 years ago! If memory serves, it was when the\n> libc6-dev package went from v2.31 to 2.35 (well 2.31-0ubuntu9.9).\n\nYes, our mails crossed.  I was just writing to linux-sparse@vger ;-)\n\n> I mentioned this problem to Luc on the sparse mailing list[1] and\n> he produced a patch which 'fixed' the problem in one way, but\n> caused a different problem[2]. Namely, because git passes -Wvla\n> to gcc, it now issues the 'used vla' warnings, which gcc does\n> not because of some '# pragma GCC diagnostic ignored \"-Wvla\"' which\n> sparse does not honor! :(\n\nSorry, but I do not follow.  Isn't -Wno-vla an instruction to sparse\nto tell it *not* to complain about use of vla?\n\nWe do not pass -Wvla or -Wno-vla to sparse ourselves.  Because the\ntool comes from the Linux land where VLA is not welcome, we'd by\ndefault get the \"hey, you used vla here---did you mean it?\" error.\n\nAnd the patch by Luc Van Oostenryck in the thread you raised at\naround the end of 2023 does apply to the tip and with\n\n\tSP_EXTRA_FLAGS += -Wno-vla\n\nin Makefile, sparse seems to be happy when I do \"make sparse\".\n"},{"id":"498850","messageId":"8dd1a2c7-5b9f-4e2f-9c5a-d5d5758714e2@ramsayjones.plus.com","threadId":"61788","inReplyTo":"xmqqr0br26ok.fsf@gitster.g","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2024-07-17T19:20:38Z","receivedAt":"2024-07-17T19:20:41Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 17/07/2024 19:51, Junio C Hamano wrote:\n> Ramsay Jones <ramsay@ramsayjones.plus.com> writes:\n[snip]\n>> I mentioned this problem to Luc on the sparse mailing list[1] and\n>> he produced a patch which 'fixed' the problem in one way, but\n>> caused a different problem[2]. Namely, because git passes -Wvla\n>> to gcc, it now issues the 'used vla' warnings, which gcc does\n>> not because of some '# pragma GCC diagnostic ignored \"-Wvla\"' which\n>> sparse does not honor! :(\n> \n> Sorry, but I do not follow.  Isn't -Wno-vla an instruction to sparse\n> to tell it *not* to complain about use of vla?\n\nIt's a warning flag for both sparse and gcc. At the time, I was trying\nto find a solution which didn't disable the warning for gcc at the same\ntime (iff you used sparse as a front-end to gcc, which people on git\ntend not to do; ie _don't_ use 'cgcc -no-compile' ;) ).\n\nAlso, I wanted a solution that didn't require setting SPARSE_FLAGS\n(SP_EXTRA_FLAGS didn't exist then) in the Makefile (only some people\nwere affected).\n\n> We do not pass -Wvla or -Wno-vla to sparse ourselves.  Because the\n> tool comes from the Linux land where VLA is not welcome, we'd by\n> default get the \"hey, you used vla here---did you mean it?\" error.\n> \n> And the patch by Luc Van Oostenryck in the thread you raised at\n> around the end of 2023 does apply to the tip and with\n> \n> \tSP_EXTRA_FLAGS += -Wno-vla\n> \n> in Makefile, sparse seems to be happy when I do \"make sparse\".\n\nYes, that works because 'make sparse' does not use cgcc as a front\nend to gcc, and the command line has -Wvla followed by -Wno-vla, so\nlast one wins (the sparse specific flags come after the gcc flags).\n\nATB,\nRamsay Jones\n\n\n"},{"id":"498882","messageId":"0e2c66ce-d870-4a03-a26e-a928183b9b2b@ramsayjones.plus.com","threadId":"61788","inReplyTo":"8dd1a2c7-5b9f-4e2f-9c5a-d5d5758714e2@ramsayjones.plus.com","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2024-07-17T22:36:46Z","receivedAt":"2024-07-17T22:36:49Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 17/07/2024 20:20, Ramsay Jones wrote:\n[snip]\n\n> (SP_EXTRA_FLAGS didn't exist then)\nThis is absolute rubbish, of course! ;)\n\nI don't know what I was thinking, but I suspect I was thinking about\nthe recent _APPEND variables - except they were only for CFLAGS and\nLDFLAGS! Ho Hum.\n\nSorry about that.\n\nATB,\nRamsay Jones\n\n\n"},{"id":"498885","messageId":"xmqq5xt33a10.fsf@gitster.g","threadId":"61788","inReplyTo":"0e2c66ce-d870-4a03-a26e-a928183b9b2b@ramsayjones.plus.com","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-17T22:53:47Z","receivedAt":"2024-07-17T22:53:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsayjones.plus.com> writes:\n\n> On 17/07/2024 20:20, Ramsay Jones wrote:\n> [snip]\n>\n>> (SP_EXTRA_FLAGS didn't exist then)\n> This is absolute rubbish, of course! ;)\n>\n> I don't know what I was thinking, but I suspect I was thinking about\n> the recent _APPEND variables - except they were only for CFLAGS and\n> LDFLAGS! Ho Hum.\n>\n> Sorry about that.\n\nThat's OK.  So in short, with a separate SP_EXTRA_FLAGS with \"-Wno-vla\",\nLuc's patch is a sufficient fix without any downsides, no?\n"},{"id":"498887","messageId":"a1a771b5-f8fb-40e3-bae0-6307abbce58a@ramsayjones.plus.com","threadId":"61788","inReplyTo":"xmqq5xt33a10.fsf@gitster.g","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2024-07-18T00:02:54Z","receivedAt":"2024-07-18T00:02:57Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 17/07/2024 23:53, Junio C Hamano wrote:\n[snip]\n> That's OK.  So in short, with a separate SP_EXTRA_FLAGS with \"-Wno-vla\",\n> Luc's patch is a sufficient fix without any downsides, no?\n> \n\nYes, assuming you're only concerned with 'make sparse' usage.\n\nBTW, I didn't expect it to take this long for this issue to come\nback to the list! I expected it to almost immediately cause\nproblems with the sparse ci job, when the version of Ubuntu was\nupdated to the LTS (now previous LTS!). So, I just found a simple\nsolution for now (which turned into 2 years).\n\nATB,\nRamsay Jones\n"},{"id":"498893","messageId":"ZpiAcJuAH50UlHIX@danh.dev","threadId":"61788","inReplyTo":"a1a771b5-f8fb-40e3-bae0-6307abbce58a@ramsayjones.plus.com","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2024-07-18T02:39:44Z","receivedAt":"2024-07-18T02:39:46Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2024-07-18 01:02:54+0100, Ramsay Jones <ramsay@ramsayjones.plus.com> wrote:\n> \n> \n> On 17/07/2024 23:53, Junio C Hamano wrote:\n> [snip]\n> > That's OK.  So in short, with a separate SP_EXTRA_FLAGS with \"-Wno-vla\",\n> > Luc's patch is a sufficient fix without any downsides, no?\n> > \n> \n> Yes, assuming you're only concerned with 'make sparse' usage.\n> \n> BTW, I didn't expect it to take this long for this issue to come\n> back to the list! I expected it to almost immediately cause\n> problems with the sparse ci job, when the version of Ubuntu was\n> updated to the LTS (now previous LTS!). So, I just found a simple\n> solution for now (which turned into 2 years).\n\nWell, yeah, -Wno-vla would work, I used that macro __STDC_NO_VLA__\nbecause I'm not sure Git want to use vla or not, so I only tried to\ndisable it for system headers.\n\nAnd yes, the vla declarationw as added into glibc 2.35.\n\n-- \nDanh\n"},{"id":"498895","messageId":"xmqqplrb1f2p.fsf@gitster.g","threadId":"61788","inReplyTo":"a1a771b5-f8fb-40e3-bae0-6307abbce58a@ramsayjones.plus.com","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-18T04:47:42Z","receivedAt":"2024-07-18T04:47:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsayjones.plus.com> writes:\n\n> On 17/07/2024 23:53, Junio C Hamano wrote:\n> [snip]\n>> That's OK.  So in short, with a separate SP_EXTRA_FLAGS with \"-Wno-vla\",\n>> Luc's patch is a sufficient fix without any downsides, no?\n>> \n>\n> Yes, assuming you're only concerned with 'make sparse' usage.\n\nIs there anything else in the context of this project I should be\nconcerned with, wrt sparse and recent </usr/include/regex.h> that\nuses vla in prototype parameters?\n\n> BTW, I didn't expect it to take this long for this issue to come\n> back to the list! I expected it to almost immediately cause\n> problems with the sparse ci job, when the version of Ubuntu was\n> updated to the LTS (now previous LTS!). So, I just found a simple\n> solution for now (which turned into 2 years).\n\n;-)\n\nThanks.  It really makes me appreciate whenever I learn that we are\nblessed with project friends who are involved in many other projects\nwe rely on.\n"},{"id":"498899","messageId":"xmqqzfqfyy7q.fsf@gitster.g","threadId":"61788","inReplyTo":"ZpiAcJuAH50UlHIX@danh.dev","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-18T07:07:53Z","receivedAt":"2024-07-18T07:07:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh <congdanhqx@gmail.com> writes:\n\n>> BTW, I didn't expect it to take this long for this issue to come\n>> back to the list! I expected it to almost immediately cause\n>> problems with the sparse ci job, when the version of Ubuntu was\n>> updated to the LTS (now previous LTS!). So, I just found a simple\n>> solution for now (which turned into 2 years).\n>\n> Well, yeah, -Wno-vla would work, I used that macro __STDC_NO_VLA__\n> because I'm not sure Git want to use vla or not, so I only tried to\n> disable it for system headers.\n\nDefining __STDC_NO_VLA__ would rid use of variable length arrays in\nthe regex.h header, so \"-Wno-vla\" would not be necessary.  It's just\nthat it makes me feel a bit dirty to define the macro that only\ncompiler implementations are expected to define in order to cause\nheader files behave the way they would with a compiler without VLA.\n\nIf we apply Luc's patch [*1*] to sparse, the header would use vla in\nparameter in the prototype, sparse would grok it, *and* then\ncomplain that we are using vla, so we still need \"-Wno-vla\" on top\n(but \"-Wno-vla\" alone would not make (unpatched) sparse grok the\nconstruct, of course).\n\n> And yes, the vla declarationw as added into glibc 2.35.\n\nThanks.\n\n\n[Reference]\n\n*1* https://lore.kernel.org/all/uug4xslokvlxr6z24q52z4pt7nrtiimbzunz2gz3kpilk4kxts@7jljsksi6baq/\n"},{"id":"498911","messageId":"ZpjWYHvCa_Sb_wwk@danh.dev","threadId":"61788","inReplyTo":"ZpiAcJuAH50UlHIX@danh.dev","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2024-07-18T08:46:24Z","receivedAt":"2024-07-18T08:46:28Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2024-07-18 09:39:44+0700, Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:\n> On 2024-07-18 01:02:54+0100, Ramsay Jones <ramsay@ramsayjones.plus.com> wrote:\n> > \n> > \n> > On 17/07/2024 23:53, Junio C Hamano wrote:\n> > [snip]\n> > > That's OK.  So in short, with a separate SP_EXTRA_FLAGS with \"-Wno-vla\",\n> > > Luc's patch is a sufficient fix without any downsides, no?\n> > > \n> > \n> > Yes, assuming you're only concerned with 'make sparse' usage.\n> > \n> > BTW, I didn't expect it to take this long for this issue to come\n> > back to the list! I expected it to almost immediately cause\n> > problems with the sparse ci job, when the version of Ubuntu was\n> > updated to the LTS (now previous LTS!). So, I just found a simple\n> > solution for now (which turned into 2 years).\n> \n> Well, yeah, -Wno-vla would work, I used that macro __STDC_NO_VLA__\n> because I'm not sure Git want to use vla or not, so I only tried to\n> disable it for system headers.\n\nEh, I replied too soon, -Wno-vla doesn't work with my compiler:\n\n     $ rm -f builtin/am.sp && make V=1 builtin/am.sp\n     cgcc -no-compile -I. -I.   -fstack-protector-strong -D_FORTIFY_SOURCE=2 -pipe -O2 -g -march=native  -I. -DHAVE_SYSINFO -DGIT_HOST_CPU=\"\\\"x86_64\\\"\" -DHAVE_ALLOCA_H  -DUSE_CURL_FOR_IMAP_SEND -DSUPPORTS_SIMPLE_IPC -DSHA1_DC -DSHA1DC_NO_STANDARD_INCLUDES -DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 -DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"\\\"git-compat-util.h\\\"\" -DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"\\\"git-compat-util.h\\\"\" -DSHA256_BLK  -DHAVE_PATHS_H -DHAVE_DEV_TTY -DHAVE_CLOCK_GETTIME -DHAVE_CLOCK_MONOTONIC -DHAVE_SYNC_FILE_RANGE -DHAVE_GETDELIM '-DPROCFS_EXECUTABLE_PATH=\"/proc/self/exe\"' -DFREAD_READS_DIRECTORIES -DNO_STRLCPY -DSHELL_PATH='\"/bin/sh\"'  \\\n            -Wsparse-error \\\n            -std=gnu99 -Wno-universal-initializer -Wno-vla builtin/am.c && \\\n     >builtin/am.sp\n    builtin/am.c: note: in included file (through git-compat-util.h, builtin.h):\n    /usr/include/regex.h:682:41: error: undefined identifier '__nmatch'\n    /usr/include/regex.h:682:41: error: bad constant expression type\n    make: *** [Makefile:3263: builtin/am.sp] Error 1\n\n    $ gcc --version\n    gcc (GCC) 13.2.0\n    Copyright (C) 2023 Free Software Foundation, Inc.\n    This is free software; see the source for copying conditions.  There is NO\n    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n\n\n-- \nDanh\n"},{"id":"498952","messageId":"28fd393a-2d8a-4019-95bc-d1a2e409cf53@ramsayjones.plus.com","threadId":"61788","inReplyTo":"xmqqplrb1f2p.fsf@gitster.g","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2024-07-19T02:03:19Z","receivedAt":"2024-07-19T02:03:28Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 18/07/2024 05:47, Junio C Hamano wrote:\n> Ramsay Jones <ramsay@ramsayjones.plus.com> writes:\n> \n>> On 17/07/2024 23:53, Junio C Hamano wrote:\n>> [snip]\n>>> That's OK.  So in short, with a separate SP_EXTRA_FLAGS with \"-Wno-vla\",\n>>> Luc's patch is a sufficient fix without any downsides, no?\n>>>\n>>\n>> Yes, assuming you're only concerned with 'make sparse' usage.\n> \n> Is there anything else in the context of this project I should be\n> concerned with, wrt sparse and recent </usr/include/regex.h> that\n> uses vla in prototype parameters?\n\nNo, I don't think so. At the time I remember looking around for more\nuses of VLA's in the glibc header files and finding nothing of concern:\n\n  $ find /usr/include -iname '*.h' |\n  > xargs grep -n __STDC_NO_VLA__\n  /usr/include/regex.h:527:\t&& !defined __STDC_NO_VLA__)\n  /usr/include/brotli/port.h:251:    !defined(__STDC_NO_VLA__) && !defined(__cplusplus) &&         \\\n  $ \n\nThe <regex.h> header has only a single use of the _REGEX_NELTS macro\nin the declaration of the regexec() function.\n\nThe <brotli/port.h> header defines an BROTLI_ARRAY_PARAM macro, but does\nnot use it in the header file. It is available for use in your own source\nfile, but ...\n\nI suppose it is possible that other headers use VLA's in their declarations\nand are not protected by __STDC_NO_VLA__, but that seems unlikely. The headers\nthat we actually use (for the symbols we use), can't include any VLA's or gcc\nwould complain (via -Wvla).\n\nAlso, it seems <regex.h> is the only header that suppresses -Wvla:\n\n  $ find /usr/include -iname '*.h' |\n  > xargs grep -n '\\-Wvla'\n  /usr/include/regex.h:536:# pragma GCC diagnostic ignored \"-Wvla\"\n  $ \n\n\nATB,\nRamsay Jones\n\n"},{"id":"515896","messageId":"77f82414-261c-d2bc-f911-ed3d4b06c86e@gmx.de","threadId":"61788","inReplyTo":"a667da3985a0fe943cc0ff6ee8513d731d75a299.1721171853.git.congdanhqx@gmail.com","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2025-04-08T20:56:33Z","receivedAt":"2025-04-08T20:56:35Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Danh,\n\nOn Wed, 17 Jul 2024, Đoàn Trần Công Danh wrote:\n\n> With at least glibc 2.39, glibc provides a function declaration that\n> matches with this POSIX interface:\n>\n>     int regexec(const regex_t *restrict preg, const char *restrict string,\n>            size_t nmatch, regmatch_t pmatch[restrict], int eflags);\n>\n> such prototype requires variable-length-array for `pmatch'.\n>\n> Thus, sparse reports this error:\n>\n> > ../add-patch.c: note: in included file (through ../git-compat-util.h):\n> > /usr/include/regex.h:682:41: error: undefined identifier '__nmatch'\n> > /usr/include/regex.h:682:41: error: bad constant expression type\n> > /usr/include/regex.h:682:41: error: Variable length array is used.\n>\n> Note: `__nmatch' is POSIX's nmatch.\n>\n> The glibc's intention is informing their users to provides a large\n> enough buffer to hold `__nmatch' results and provides diagnosis if\n> necessary.  It's merely a glibc' implementation detail.\n>\n> Hide that usage from sparse by using standard C11's macro:\n> __STDC_NO_VLA__\n>\n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n>  Makefile | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/Makefile b/Makefile\n> index bc81d3395032a..4b9daca1dcc58 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1381,7 +1381,7 @@ ARFLAGS = rcs\n>  PTHREAD_CFLAGS =\n>\n>  # For the 'sparse' target\n> -SPARSE_FLAGS ?= -std=gnu99\n> +SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__\n>  SP_EXTRA_FLAGS = -Wno-universal-initializer\n>\n>  # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets\n> --\n> 2.45.2.599.g51c0d632d3b6f\n\nThank you for this patch!\n\nDue to the brownouts today (see\nhttps://github.com/actions/runner-images/issues/11101, surfaced e.g. in\nhttps://github.com/git/git/actions/runs/14342895944/job/40206357016), your\npatch came in handy, as it is required for the following fix:\n\n-- snipsnap --\nSubject: [PATCH] ci: upgrade `sparse` to supported build agents\n\nThe `sparse` job still uses the `ubuntu-20.04` runner pool, but that\npool is about to go away, so let's stop using it.\n\nThere is no `sparse-22.04` artifact provided by the \"Build sparse for\nUbuntu\" Azure Pipeline, but that is not necessary anyway because Ubuntu\n22.04 has the `sparse` package: https://packages.ubuntu.com/jammy/sparse\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n .github/workflows/main.yml | 11 +----------\n ci/install-dependencies.sh |  2 +-\n 2 files changed, 2 insertions(+), 11 deletions(-)\n\ndiff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\nindex ff44c0a8c067..c9455246269d 100644\n--- a/.github/workflows/main.yml\n+++ b/.github/workflows/main.yml\n@@ -449,20 +449,11 @@ jobs:\n     if: needs.ci-config.outputs.enabled == 'yes'\n     env:\n       jobname: sparse\n-    runs-on: ubuntu-20.04\n+    runs-on: ubuntu-22.04\n     concurrency:\n       group: sparse-${{ github.ref }}\n       cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}\n     steps:\n-    - name: Download a current `sparse` package\n-      # Ubuntu's `sparse` version is too old for us\n-      uses: git-for-windows/get-azure-pipelines-artifact@v0\n-      with:\n-        repository: git/git\n-        definitionId: 10\n-        artifact: sparse-20.04\n-    - name: Install the current `sparse` package\n-      run: sudo dpkg -i sparse-20.04/sparse_*.deb\n     - uses: actions/checkout@v4\n     - name: Install other dependencies\n       run: ci/install-dependencies.sh\ndiff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh\nindex 0df74610d063..8700c0f2924d 100755\n--- a/ci/install-dependencies.sh\n+++ b/ci/install-dependencies.sh\n@@ -119,7 +119,7 @@ StaticAnalysis)\n sparse)\n \tsudo apt-get -q update -q\n \tsudo apt-get -q -y install libssl-dev libcurl4-openssl-dev \\\n-\t\tlibexpat-dev gettext zlib1g-dev\n+\t\tlibexpat-dev gettext zlib1g-dev sparse\n \t;;\n Documentation)\n \tsudo apt-get -q update\n--\n2.49.0.windows.1\n"},{"id":"515902","messageId":"xmqq34eiuvry.fsf@gitster.g","threadId":"61788","inReplyTo":"77f82414-261c-d2bc-f911-ed3d4b06c86e@gmx.de","subject":"Re: [PATCH] sparse: ignore warning from new glibc headers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-04-08T22:35:13Z","receivedAt":"2025-04-08T22:35:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Due to the brownouts today (see\n> https://github.com/actions/runner-images/issues/11101, surfaced e.g. in\n> https://github.com/git/git/actions/runs/14342895944/job/40206357016), your\n> patch came in handy, as it is required for the following fix:\n\nGood timing ;-)\ncf. https://lore.kernel.org/git/xmqqo6x6wgs8.fsf@gitster.g/\n\n>\n> -- snipsnap --\n\nDoes mailinfo consider this as a scissors line?\n\n> Subject: [PATCH] ci: upgrade `sparse` to supported build agents\n>\n> The `sparse` job still uses the `ubuntu-20.04` runner pool, but that\n> pool is about to go away, so let's stop using it.\n>\n> There is no `sparse-22.04` artifact provided by the \"Build sparse for\n> Ubuntu\" Azure Pipeline, but that is not necessary anyway because Ubuntu\n> 22.04 has the `sparse` package: https://packages.ubuntu.com/jammy/sparse\n\nPerfect.  Will take a look.\n\nThanks.\n\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>  .github/workflows/main.yml | 11 +----------\n>  ci/install-dependencies.sh |  2 +-\n>  2 files changed, 2 insertions(+), 11 deletions(-)\n>\n> diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\n> index ff44c0a8c067..c9455246269d 100644\n> --- a/.github/workflows/main.yml\n> +++ b/.github/workflows/main.yml\n> @@ -449,20 +449,11 @@ jobs:\n>      if: needs.ci-config.outputs.enabled == 'yes'\n>      env:\n>        jobname: sparse\n> -    runs-on: ubuntu-20.04\n> +    runs-on: ubuntu-22.04\n>      concurrency:\n>        group: sparse-${{ github.ref }}\n>        cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}\n>      steps:\n> -    - name: Download a current `sparse` package\n> -      # Ubuntu's `sparse` version is too old for us\n> -      uses: git-for-windows/get-azure-pipelines-artifact@v0\n> -      with:\n> -        repository: git/git\n> -        definitionId: 10\n> -        artifact: sparse-20.04\n> -    - name: Install the current `sparse` package\n> -      run: sudo dpkg -i sparse-20.04/sparse_*.deb\n>      - uses: actions/checkout@v4\n>      - name: Install other dependencies\n>        run: ci/install-dependencies.sh\n> diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh\n> index 0df74610d063..8700c0f2924d 100755\n> --- a/ci/install-dependencies.sh\n> +++ b/ci/install-dependencies.sh\n> @@ -119,7 +119,7 @@ StaticAnalysis)\n>  sparse)\n>  \tsudo apt-get -q update -q\n>  \tsudo apt-get -q -y install libssl-dev libcurl4-openssl-dev \\\n> -\t\tlibexpat-dev gettext zlib1g-dev\n> +\t\tlibexpat-dev gettext zlib1g-dev sparse\n>  \t;;\n>  Documentation)\n>  \tsudo apt-get -q update\n> --\n> 2.49.0.windows.1\n"}]}