linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: Sparse preprocessing bug with zero-arg variadic macros
Date: Thu, 31 Aug 2017 14:34:44 -0700	[thread overview]
Message-ID: <20170831213444.6yeyfcrry6utaeih@cloud> (raw)
In-Reply-To: <20170831210922.GA9227@ZenIV.linux.org.uk>

On Thu, Aug 31, 2017 at 10:09:22PM +0100, Al Viro wrote:
> On Thu, Aug 31, 2017 at 09:54:33PM +0100, Al Viro wrote:
> > What a mess...  Note that for non-vararg it *is* the right interpretation
> > (with #define A(x) [x] we will have A() interpreted as "empty token sequence
> > as the only argument", not "no arguments given").  For vararg case we
> > normally do not need to distinguish "not given" and "empty" - the only
> > thing that cares is exactly the ,## kludge.  There with
> > #define B(x,...) [x,##__VA_ARGS__]
> > B(1) and B(1,) yield [1] and [1,] resp.  And for everything other than
> > "just ..." we even get it right...
> > 
> > I see what's going on there; will post a fix in a few.
> 
> 
> Fix macro argument parsing for (...) case
> 
> Nasty corner case for the sake of ,##__VA_ARGS__ perversion - for something
> like #define A(x,...) [x,##__VA_ARGS] we want A(1) to expand to [1] and
> A(1,) - to [1,].  In other words, "no vararg given" and "vararg empty" are
> different and need to be distinguished.  Unfortunately, in case when there
> was nothing but vararg we got it wrong - #define A(...) ,##__VA_ARGS ended
> up with A() interpreted as "one empty argument" (as it would in non-vararg
> case) rather than "zero arguments".
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
> diff --git a/pre-process.c b/pre-process.c
> index 74414df..8800dce 100644
> --- a/pre-process.c
> +++ b/pre-process.c
> @@ -296,9 +296,11 @@ static int collect_arguments(struct token *start, struct token *arglist, struct
>  		for (count = 0; count < wanted; count++) {
>  			struct argcount *p = &arglist->next->count;
>  			next = collect_arg(start, p->vararg, &what->pos, p->normal);
> -			arglist = arglist->next->next;
>  			if (eof_token(next))
>  				goto Eclosing;
> +			if (p->vararg && wanted == 1 && eof_token(start->next))
> +				break;
> +			arglist = arglist->next->next;
>  			args[count].arg = start->next;
>  			args[count].n_normal = p->normal;
>  			args[count].n_quoted = p->quoted;

This looks plausible; we should also add a test for it, though.

  reply	other threads:[~2017-08-31 21:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 13:34 Sparse preprocessing bug with zero-arg variadic macros Josh Poimboeuf
2017-08-31 17:19 ` Linus Torvalds
2017-08-31 20:54   ` Al Viro
2017-08-31 21:09     ` Al Viro
2017-08-31 21:34       ` Josh Triplett [this message]
2017-08-31 21:48         ` Al Viro
2017-09-01  0:06           ` Christopher Li

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=20170831213444.6yeyfcrry6utaeih@cloud \
    --to=josh@joshtriplett.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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 NNTP newsgroup(s).