From patchwork Mon Nov 19 20:51:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFC6F14BD for ; Mon, 19 Nov 2018 20:51:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0F022A5C7 for ; Mon, 19 Nov 2018 20:51:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A53DB2A5BF; Mon, 19 Nov 2018 20:51:37 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 2F2962A4D7 for ; Mon, 19 Nov 2018 20:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730831AbeKTHRA (ORCPT ); Tue, 20 Nov 2018 02:17:00 -0500 Received: from avasout04.plus.net ([212.159.14.19]:52614 "EHLO avasout04.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730797AbeKTHRA (ORCPT ); Tue, 20 Nov 2018 02:17:00 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqW7g9pgsYyh2OqW8gYm5l; Mon, 19 Nov 2018 20:51:36 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=MoN8FVSe c=1 sm=1 tr=0 a=VCDsReDbrwk4B7AcQzWGLw==:117 a=VCDsReDbrwk4B7AcQzWGLw==:17 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=12FQXpHfvSKBQcDQCmAA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 6/9] pre-process: print variable argument macros correctly Message-ID: <91253db3-6c8e-2b2f-0672-73b804b26ac2@ramsayjones.plus.com> Date: Mon, 19 Nov 2018 20:51:33 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Language: en-GB X-CMAE-Envelope: MS4wfEqmRjmEUUbTl4rJJMgKUX9BYpkRfxvSs9SaQKaeYJzs7s6UzAtIO4tCA2X3r8nqEVPg6usmo1e83nmliit+ITcJv18GJ97kYv/dEj+wWKMSjIVbmi4z CLhTSnxoe6p0wCwMpYWhRvP0qHqWVJvLL5OeuI4PzSMCbVpLbFtSlU/HWIAK1pK9jI/v5twZmGA5SA== 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 The dump_macros() function fails to correctly output the definition of macros that have a variable argument list. For example, the following macros: #define unlocks(...) annotate(unlock_func(__VA_ARGS__)) #define apply(x,...) x(__VA_ARGS__) are output like so: #define unlocks(__VA_ARGS__) annotate(unlock_func(__VA_ARGS__)) #define apply(x,__VA_ARGS__) x(__VA_ARGS__) Add the code necessary to print the ellipsis in the argument list to the dump_macros() function and add the above macros to the 'dump-macros.c' test file. Signed-off-by: Ramsay Jones --- pre-process.c | 11 ++++++++++- validation/preprocessor/dump-macros.c | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pre-process.c b/pre-process.c index 7b76c65..418b8ee 100644 --- a/pre-process.c +++ b/pre-process.c @@ -2167,6 +2167,12 @@ struct token * preprocess(struct token *token) return token; } +static int is_VA_ARGS_token(struct token *token) +{ + return (token_type(token) == TOKEN_IDENT) && + (token->ident == &__VA_ARGS___ident); +} + static void dump_macro(struct symbol *sym) { int nargs = sym->arglist ? sym->arglist->count.normal : 0; @@ -2182,7 +2188,10 @@ static void dump_macro(struct symbol *sym) for (; !eof_token(token); token = token->next) { if (token_type(token) == TOKEN_ARG_COUNT) continue; - printf("%s%s", sep, show_token(token)); + if (is_VA_ARGS_token(token)) + printf("%s...", sep); + else + printf("%s%s", sep, show_token(token)); args[narg++] = token; sep = ","; } diff --git a/validation/preprocessor/dump-macros.c b/validation/preprocessor/dump-macros.c index f8983d8..6940a20 100644 --- a/validation/preprocessor/dump-macros.c +++ b/validation/preprocessor/dump-macros.c @@ -9,6 +9,9 @@ #define STRING(x) #x #define CONCAT(x,y) x ## y + +#define unlocks(...) annotate(unlock_func(__VA_ARGS__)) +#define apply(x,...) x(__VA_ARGS__) /* * check-name: dump-macros * check-command: sparse -E -dD -DIJK=ijk -UNDEF -UNYDEF $file @@ -20,4 +23,6 @@ check-output-contains: #define DEF xyz check-output-contains: #define NYDEF ydef check-output-contains: #define STRING(x) #x check-output-contains: #define CONCAT(x,y) x ## y +check-output-contains: #define unlocks(...) annotate(unlock_func(__VA_ARGS__)) +check-output-contains: #define apply(x,...) x(__VA_ARGS__) */