From: Paul Eggert <eggert@cs.ucla.edu>
To: Martin Sebor <msebor@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] remove attribute access from regexec
Date: Wed, 18 Aug 2021 12:52:16 -0700 [thread overview]
Message-ID: <1024a9e9-a880-7da2-7b99-3e8b8012a94a@cs.ucla.edu> (raw)
In-Reply-To: <bebb6028-ddae-67f7-e14c-7f95b733c7cc@gmail.com>
On 8/14/21 1:08 PM, Martin Sebor wrote:
> The VLA bound by itself doesn't affect codegen. I suspect you're
> thinking of a[static n]? With just a[n], without static, there
> is no requirement that a point to an array with n elements. It
> simply declares an ordinary pointer, same as [] or *.
Thanks for clarifying.
I tried using a patch like that on coreutils, but it caused the build to
fail like this:
In file included from lib/exclude.c:35:
./lib/regex.h:661:7: error: ISO C90 forbids variable length array
'__pmatch' [-Werror=vla]
661 | regmatch_t __pmatch[_Restrict_arr_ _VLA_ARG (__nmatch)],
| ^~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:10648: lib/exclude.o] Error 1
This is because coreutils is compiled with -Wvla -Werror, to catch
inadvertent attempts to use VLAs in local variables (this helps avoid
stack-overflow problems). It'd be unfortunate if we had to give that
useful diagnostic up simply due to this declaration, as there's no
stack-overflow problem here.
If you can think of a way around this issue, here are some other things
I ran into while trying this idea out on Coreutils.
* Other cdefs.h macros (__NTH, __REDIRECT, etc.) start with two
underscores, so shouldn't this new macro too?
* Come to think of it, the name _VLA_ARG could be improved, as its
argument is not actually a VLA; it's the number of elements in a
VLA-like array. Also, its formal-parameter "arg" is confusingly-named,
as it's an arbitrary integer expression and need not be a function
parameter name. How about naming the macro __ARG_NELTS instead?
* regex.h cannot use __ARG_NELTS directly, for the same reason it can't
use __restrict_arr directly: regex.h is shared with Gnulib and can't
assume that a glibc-like sys/cdefs.h is present. I suppose regex.h would
need something like this:
#ifndef _ARG_NELTS_
# ifdef __ARG_NELTS
# define _ARG_NELTS_(arg) __ARG_NELTS (arg)
# elif (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
&& !defined __STDC_NO_VLA__)
# define _ARG_NELTS_(n) n
# else
# define _ARG_NELTS_(n)
# endif
#endif
and then use _ARG_NELTS_ later.
* The cdefs.h comment has a stray 'n', its wording could be improved (I
misread "variable bound" as a variable that's bound to something),
there's a stray empty line, and it's nicer to put the comment in front
of all the lines that define the macro. Perhaps something like this:
/* Specify the number of elements of a function's array parameter,
as in 'int f (int n, int a[__ARG_NELTS (n)]);'. */
#if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
&& !defined __STDC_NO_VLA__)
# define __ARG_NELTS(n) n
#else
# define __ARG_NELTS(n)
#endif
Though again, it's not clear to me that this idea will fly at all, due
to the -Wvla issue.
Maybe GCC's -Wvla should be fixed to not report an error in this case?
It's actually not a VLA if you ask me (the C standard is unclear).
next prev parent reply other threads:[~2021-08-18 19:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 18:26 Martin Sebor
2021-08-13 20:11 ` Paul Eggert
2021-08-13 21:30 ` Martin Sebor
2021-08-13 22:34 ` Paul Eggert
2021-08-14 20:08 ` Martin Sebor
2021-08-18 15:53 ` [PATCH v2] " Martin Sebor
2021-08-18 19:52 ` Paul Eggert [this message]
2021-08-19 23:50 ` [PATCH v3] " Martin Sebor
2021-08-22 5:06 ` Paul Eggert
2021-08-26 15:06 ` Martin Sebor
2021-08-26 16:24 ` Paul Eggert
2021-08-26 16:47 ` Martin Sebor
2021-08-27 8:52 ` Paul Eggert
2021-08-27 16:34 ` Martin Sebor
2021-08-27 17:50 ` Allow #pragma GCC in headers in conformtest [committed] (was: Re: [PATCH v3] remove attribute access from regexec) Joseph Myers
2021-08-27 18:57 ` [PATCH v3] remove attribute access from regexec Paul Eggert
2021-09-20 20:46 ` Joseph Myers
2021-09-21 6:52 ` Paul Eggert
2021-09-21 13:48 ` Joseph Myers
2021-09-21 15:00 ` Paul Eggert
2021-10-19 16:39 ` Carlos O'Donell
2021-10-19 17:06 ` Martin Sebor
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=1024a9e9-a880-7da2-7b99-3e8b8012a94a@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=libc-alpha@sourceware.org \
--cc=msebor@gmail.com \
/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 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 read-only IMAP folder(s) and NNTP newsgroup(s).