linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sparse regex error
@ 2023-12-20  0:18 Ramsay Jones
  2023-12-20 23:13 ` Luc Van Oostenryck
  0 siblings, 1 reply; 4+ messages in thread
From: Ramsay Jones @ 2023-12-20  0:18 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Sparse Mailing-list

Hi Luc,

Long time no hear! ;)

About 18 months ago, I updated my Linux installation and sparse started
to fail when run during my git build. The reason for the failure was,
ultimately, a change to the 'regex.h' header file as a result of the
update from one Ubuntu LTS base to the current Ubuntu LTS base.
In particular, an update to the libc6-devel package from 2.31 to 2.35
which (in part) looked like this:

.

524a525,548
> #ifndef _REGEX_NELTS
> # if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
>       && !defined __STDC_NO_VLA__)
> #  define _REGEX_NELTS(n) n
> # else
> #  define _REGEX_NELTS(n)
> # endif
> #endif
> 

.

645c681,682
<                   regmatch_t __pmatch[_Restrict_arr_],
---
>                   regmatch_t __pmatch[_Restrict_arr_
>                                       _REGEX_NELTS (__nmatch)],

.

The last hunk is the declaration of regexec(), thus:

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);

To fix my build, I added the following to my config.mak file on linux:

    SPARSE_FLAGS += -D__STDC_NO_VLA__

. and immediately started working on a fix to sparse! Oh wait ... :)

I did report the problem and the above workaround on the git ML [1], and
created a test in my sparse repo to demonstrate the problem, thus:

  $ git diff
  diff --git a/validation/restrict-array.c b/validation/restrict-array.c
  index 04bfdad9..86753b7d 100644
  --- a/validation/restrict-array.c
  +++ b/validation/restrict-array.c
  @@ -29,9 +29,19 @@ typedef unsigned long int size_t;
   
   extern int regexec (const regex_t *__restrict __preg,
                      const char *__restrict __string, size_t __nmatch,
  -                   regmatch_t __pmatch[__restrict_arr],
  +                   regmatch_t __pmatch[__restrict_arr __nmatch],
                      int __eflags);
   
  +static int call_regexec(const regex_t *r)
  +{
  +       char s[] = "something to search";
  +       regmatch_t pm[5];
  +
  +       if (regexec(r, s, 5, pm, 0))
  +               return 0;
  +       return 1;
  +}
  +
   /*
    * check-name: restrict array attribute
    */
  $ 

which, similarly to git, shows errors not on the declaration of the
regexec() function, but on each call site (about a dozen in git):

  $ ./sparse validation/restrict-array.c
  validation/restrict-array.c:32:56: error: undefined identifier '__nmatch'
  validation/restrict-array.c:32:56: error: bad constant expression type
  $ 

I have tried to find the time, in the last couple of days, to take a look
and find a fix for this, but I have had to admit defeat and just content
myself with noting the problem here. :(

Maybe I will find some time over the xmas break.

[1] https://lore.kernel.org/git/7498bff0-782f-8c81-5817-ed841f12dbba@ramsayjones.plus.com/

ATB,
Ramsay Jones


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-17 18:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-20  0:18 sparse regex error Ramsay Jones
2023-12-20 23:13 ` Luc Van Oostenryck
2023-12-21  1:45   ` Ramsay Jones
2024-07-17 18:44   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).