From patchwork Thu Aug 31 21:48:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 9932975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 001496022E for ; Thu, 31 Aug 2017 21:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E77EB2621B for ; Thu, 31 Aug 2017 21:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC43D2623C; Thu, 31 Aug 2017 21:48:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 718082621B for ; Thu, 31 Aug 2017 21:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751581AbdHaVsN (ORCPT ); Thu, 31 Aug 2017 17:48:13 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:54210 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751693AbdHaVsM (ORCPT ); Thu, 31 Aug 2017 17:48:12 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1dnXJq-0003di-EH; Thu, 31 Aug 2017 21:48:10 +0000 Date: Thu, 31 Aug 2017 22:48:10 +0100 From: Al Viro To: Josh Triplett Cc: Linus Torvalds , Josh Poimboeuf , Sparse Mailing-list Subject: Re: Sparse preprocessing bug with zero-arg variadic macros Message-ID: <20170831214810.GS5426@ZenIV.linux.org.uk> References: <20170831133400.zjeaxhf25rbdftic@treble> <20170831205433.GQ5426@ZenIV.linux.org.uk> <20170831210922.GA9227@ZenIV.linux.org.uk> <20170831213444.6yeyfcrry6utaeih@cloud> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170831213444.6yeyfcrry6utaeih@cloud> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Aug 31, 2017 at 02:34:44PM -0700, Josh Triplett wrote: > 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 > > --- > > 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. throw this in, perhaps? --- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/validation/preprocessor/preprocessor23.c b/validation/preprocessor/preprocessor23.c index 25be508..a778483 100644 --- a/validation/preprocessor/preprocessor23.c +++ b/validation/preprocessor/preprocessor23.c @@ -12,6 +12,9 @@ I(,) I(x,) I(,x) I(x,x) +#define J(...) ,##__VA_ARGS__ +J() +J(x) /* * check-name: Preprocessor #23 * check-command: sparse -E $file @@ -29,6 +32,7 @@ I(x,x) ,x ,x ,xx +,x * check-output-end * * check-error-start