From patchwork Mon Nov 19 20:49:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689423 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 1BD3514BD for ; Mon, 19 Nov 2018 20:49:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C37E2A278 for ; Mon, 19 Nov 2018 20:49:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 006A22A281; Mon, 19 Nov 2018 20:49:46 +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 7A57E2A27A for ; Mon, 19 Nov 2018 20:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730830AbeKTHPI (ORCPT ); Tue, 20 Nov 2018 02:15:08 -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 S1730797AbeKTHPI (ORCPT ); Tue, 20 Nov 2018 02:15:08 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqUJg9pVgYyh2OqUKgYm16; Mon, 19 Nov 2018 20:49:44 +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=yFQW40laQ8OLDbqpUpsA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 4/9] pre-process: print macros containing # and ## correctly Message-ID: <9704c8a7-1802-efc5-0bea-0e0a9901e72d@ramsayjones.plus.com> Date: Mon, 19 Nov 2018 20:49:42 +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: MS4wfLBHUcl2idgh3IP2N1fk9RybDjT/gYDc+HPVfXNBdZiTqcK59Ge9Nrz7q0Sib+NMW0uIQ11QxcS+J+n5dElw95v3Gpzih2o4IpSwMERWUkherJCxJ+U1 /6RfHFd4gmfxPw1/rOmYq8At4Kcm2lf6NlojtVkZXyCjcXPXxtjOVOwW21UzPX/Eh4jsoa5bM0MJ4w== 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_macro() function fails to correctly output the definitions of macros that contain the string operator '#', the concatenation operator '##' and any macro parameter in the definition token list. For example, the following macros: #define STRING(x) #x #define CONCAT(x,y) x ## y are output like so: #define STRING(x) unhandled token type '21' #define CONCAT(x, y) unhandled token type '22' unhandled token type '23' unhandled token type '22' Add the code necessary to handle those token types 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 | 7 +++++++ validation/preprocessor/dump-macros.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/pre-process.c b/pre-process.c index 8abd5e6..eca7ab5 100644 --- a/pre-process.c +++ b/pre-process.c @@ -2196,6 +2196,13 @@ static void dump_macro(struct symbol *sym) switch (token_type(token)) { case TOKEN_UNTAINT: break; + case TOKEN_STR_ARGUMENT: + printf("#%s", show_token(args[token->argnum])); + break; + case TOKEN_CONCAT: + printf("## "); + break; + case TOKEN_QUOTED_ARGUMENT: case TOKEN_MACRO_ARGUMENT: token = args[token->argnum]; /* fall-through */ diff --git a/validation/preprocessor/dump-macros.c b/validation/preprocessor/dump-macros.c index 4dbb962..5a96464 100644 --- a/validation/preprocessor/dump-macros.c +++ b/validation/preprocessor/dump-macros.c @@ -6,6 +6,9 @@ #define DEF xyz #define NYDEF ydef + +#define STRING(x) #x +#define CONCAT(x,y) x ## y /* * check-name: dump-macros * check-command: sparse -E -dD -DIJK=ijk -UNDEF -UNYDEF $file @@ -15,4 +18,6 @@ check-output-pattern(1): #define __CHECKER__ 1 check-output-contains: #define IJK ijk 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 */