All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] sparse: ignore warning from new glibc headers
Date: Wed, 17 Jul 2024 09:54:05 -0700	[thread overview]
Message-ID: <xmqqikx42c42.fsf@gitster.g> (raw)
In-Reply-To: <a667da3985a0fe943cc0ff6ee8513d731d75a299.1721171853.git.congdanhqx@gmail.com> ("Đoàn Trần Công Danh"'s message of "Wed, 17 Jul 2024 06:17:41 +0700")

Đoàn Trần Công Danh <congdanhqx@gmail.com> writes:

> With at least glibc 2.39, glibc provides a function declaration that
> matches with this POSIX interface:
>
>     int regexec(const regex_t *restrict preg, const char *restrict string,
>            size_t nmatch, regmatch_t pmatch[restrict], int eflags);
>
> such prototype requires variable-length-array for `pmatch'.
> ...
> Thus, sparse reports this error:
>
>> ../add-patch.c: note: in included file (through ../git-compat-util.h):
>> /usr/include/regex.h:682:41: error: undefined identifier '__nmatch'
>> /usr/include/regex.h:682:41: error: bad constant expression type
>> /usr/include/regex.h:682:41: error: Variable length array is used.

I get the same with 

	$ sparse --version
	v0.6.4-66-g0196afe1

What I have locally in /usr/include may be a bit older.  It reads
like this:

        extern int regexec (const regex_t *_Restrict_ __preg,
                            const char *_Restrict_ __String, size_t __nmatch,
                            regmatch_t __pmatch[_Restrict_arr_
                                                _REGEX_NELTS (__nmatch)],
                            int __eflags);

where _Restrct_arr_ and _Restrict_ would become an empty string for
older compilers, and _REGEX_NELTS(foo) becomes empty when VLA is not
available.  I think their intention, when the compiler fully supports
all the necessary features, is to turn the fourth parameter into

	regmatch_t __pmatch[restrict __nmatch]

I can see how your patch forces the fourth parameter to become (ISO C99)

	regmatch_t __pmatch[restrict]

or even plain vanilla

	regmatch_t __pmatch[]

to erase the mention of __nmatch that is not understood by sparse.

> diff --git a/Makefile b/Makefile
> index bc81d3395032a..4b9daca1dcc58 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1381,7 +1381,7 @@ ARFLAGS = rcs
>  PTHREAD_CFLAGS =
>  
>  # For the 'sparse' target
> -SPARSE_FLAGS ?= -std=gnu99
> +SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
>  SP_EXTRA_FLAGS = -Wno-universal-initializer
>  
>  # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets

But it makes me feel a bit dirty to define the macro that only
compiler implementations are expected to define (or not)[*1*] to
cause header files behave the way they would with a compiler without
VLA.  I dunno.

[Reference]

 *1* https://port70.net/~nsz/c/c11/n1570.html#6.10.8p2

  reply	other threads:[~2024-07-17 16:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 23:17 [PATCH] sparse: ignore warning from new glibc headers Đoàn Trần Công Danh
2024-07-17 16:54 ` Junio C Hamano [this message]
2024-07-17 18:40   ` Ramsay Jones
2024-07-17 18:51     ` Junio C Hamano
2024-07-17 19:20       ` Ramsay Jones
2024-07-17 22:36         ` Ramsay Jones
2024-07-17 22:53           ` Junio C Hamano
2024-07-18  0:02             ` Ramsay Jones
2024-07-18  2:39               ` Đoàn Trần Công Danh
2024-07-18  7:07                 ` Junio C Hamano
2024-07-18  8:46                 ` Đoàn Trần Công Danh
2024-07-18  4:47               ` Junio C Hamano
2024-07-19  2:03                 ` Ramsay Jones
2025-04-08 20:56 ` Johannes Schindelin
2025-04-08 22:35   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqikx42c42.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=congdanhqx@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.