From patchwork Mon Nov 19 20:46:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689415 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 0939513AD for ; Mon, 19 Nov 2018 20:46:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED03929CAE for ; Mon, 19 Nov 2018 20:46:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE3D92A1A4; Mon, 19 Nov 2018 20:46:21 +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 7A7D329CAE for ; Mon, 19 Nov 2018 20:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730796AbeKTHLn (ORCPT ); Tue, 20 Nov 2018 02:11:43 -0500 Received: from avasout04.plus.net ([212.159.14.19]:52262 "EHLO avasout04.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730795AbeKTHLn (ORCPT ); Tue, 20 Nov 2018 02:11:43 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqR0g9p9bYyh2OqR1gYlqs; Mon, 19 Nov 2018 20:46:20 +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=oLey91sEAAAA:8 a=EBOSESyhAAAA:8 a=ZZy4cI5PI3BVP3g4BsgA:9 a=QEXdDO2ut3YA:10 a=D44SYiUWUjHgSrmoHUtb:22 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 1/9] sparsec: use a compatible exception model on cygwin Message-ID: <3003b5b7-1307-9d12-870b-213111d8ee3a@ramsayjones.plus.com> Date: Mon, 19 Nov 2018 20:46:17 +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: MS4wfKTTl3kx4hfmXPmfUDDTb9Smc18ZUo1/1uTrV+m4H/xbFKYkuw6tFSAWw+8r2CoKAcbfYLDJEEIu4LIcyU/DA96syS0cXyp3LlRcnyQ8WD2NEqCiZFaw kEW4jIqESOaqNo/HzFcrxgny5lCWVvfbYmSyEz63wG/W/6x0G2yi7VwKdbBheZ7OzHuTFphEdy5AvQ== 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 the cygwin platform, some of the backend tests fail due to the 'llc' tool using win32 'structured exception' assembler directives, which the platform assembler 'as' does not accept: $ make check ... TEST 'hello, world' code generation (backend/hello.c) error: actual error text does not match expected error text. error: see backend/hello.c.error.* for further investigation. --- backend/hello.c.error.expected 2018-06-03 17:14:30.550972400 +0100 +++ backend/hello.c.error.got 2018-06-03 17:14:30.478731900 +0100 @@ -0,0 +1,6 @@ +{standard input}: Assembler messages: +{standard input}:14: Error: invalid register for .seh_pushreg +{standard input}:14: Error: junk at end of line, first unrecognized character is `5' +{standard input}:20: Error: invalid register for .seh_setframe +{standard input}:20: Error: missing separator +mv: cannot stat '/tmp/tmp.oTA6mS.o': No such file or directory ... Out of 288 tests, 275 passed, 13 failed (10 of them are known to fail) make: *** [Makefile:236: check] Error 1 $ The exception model used by 'llc' can be changed from the command line to be one of 'default', 'dwarf', 'sjlj', 'arm' or 'wineh'. In this case the default is 'wineh' (windows exception handling). The 'sjlj' model is the older (setjmp,longjmp) stack-based model, which is no longer used on Linux. The newer 'dwarf' model uses a 'zero cost' table based method. (The 'arm' model is not relevant here). For more information, see [1]. After some experiments, using small test programs compiled with gcc and g++, comparing the output of tools like 'nm' and 'objdump', it seems that cygwin binutils are employing the 'sjlj' model. (Using the 'dwarf' model on 'llc' also works on simple programs). In order to fix the test failures, add an '-exception-model=sjlj' option to the 'llc' invocation when executing sparsec on the cygwin platform. [1] http://www.hexblog.com/wp-content/uploads/2012/06/Recon-2012-Skochinsky-Compiler-Internals.pdf Signed-off-by: Ramsay Jones --- sparsec | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sparsec b/sparsec index 6c60990..bafe2da 100755 --- a/sparsec +++ b/sparsec @@ -34,7 +34,17 @@ TMPFILE=`mktemp -t tmp.XXXXXX` LLC=`"${LLVM_CONFIG:-llvm-config}" --bindir`/llc -$DIRNAME/sparse-llvm $SPARSEOPTS | $LLC | as -o $TMPFILE +LLC_ARCH_OPTS= +case "$(uname -s)" in +*CYGWIN*) + # cygwin uses the sjlj (setjmp-longjmp) exception model + LLC_ARCH_OPTS="-exception-model=sjlj" + ;; +*) + ;; +esac + +$DIRNAME/sparse-llvm $SPARSEOPTS | $LLC ${LLC_ARCH_OPTS} | as -o $TMPFILE if [ $NEED_LINK -eq 1 ]; then if [ -z $OUTFILE ]; then From patchwork Mon Nov 19 20:47:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689419 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 491CD14BD for ; Mon, 19 Nov 2018 20:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 372A72A1A4 for ; Mon, 19 Nov 2018 20:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AA322A42E; Mon, 19 Nov 2018 20:47:29 +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 AC5302A1A4 for ; Mon, 19 Nov 2018 20:47:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730795AbeKTHMu (ORCPT ); Tue, 20 Nov 2018 02:12:50 -0500 Received: from avasout04.plus.net ([212.159.14.19]:52356 "EHLO avasout04.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730830AbeKTHMu (ORCPT ); Tue, 20 Nov 2018 02:12:50 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqS5g9pGNYyh2OqS6gYlu5; Mon, 19 Nov 2018 20:47:26 +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=dddas0_YW2fZw5whDPgA:9 a=m0i2RIxt19PloQar:21 a=mKL-qY9IGN-VznFl:21 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 2/9] sparsei: add the --[no-]jit options Message-ID: Date: Mon, 19 Nov 2018 20:47:23 +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: MS4wfGb3oI9ZXJA4p/n7VbwUlkX8LnsZNCWlc9QjcVc5mmHUzGOZ1lMmS0EtOh+/qijfYk6lW4rUspQHfluD8xqSPgBaXy9pyolG3L00NMnriWIH17s0mDD9 kvDKSA/ucTpFTPp4TDjK00Oee2hQZTM6z5HmCj9MiHAt25Cerd8u0whw2eeWVB1cELv2nCEifqpVfg== 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 the cygwin platform, a 'sparsei' backend test, which uses the llvm 'lli' tool, fails due to a dynamic linking error: $ make check ... TEST sum from 1 to n (backend/sum.c) error: actual output text does not match expected output text. error: see backend/sum.c.output.* for further investigation. --- backend/sum.c.output.expected 2018-06-03 18:27:11.502760500 +0100 +++ backend/sum.c.output.got 2018-06-03 18:27:11.307670000 +0100 @@ -1,2 +0,0 @@ -15 -5050 error: actual error text does not match expected error text. error: see backend/sum.c.error.* for further investigation. --- backend/sum.c.error.expected 2018-06-03 18:27:11.562997400 +0100 +++ backend/sum.c.error.got 2018-06-03 18:27:11.481038800 +0100 @@ -0,0 +1 @@ +LLVM ERROR: Program used external function 'printf' which could not be resolved! error: Actual exit value does not match the expected one. error: expected 0, got 1. ... Out of 288 tests, 277 passed, 11 failed (10 of them are known to fail) make: *** [Makefile:236: check] Error 1 $ Note the 'LLVM ERROR' about the 'printf' external function which could not be resolved (linked). On Linux, it seems that the 'lli' tool (JIT compiler) can resolve the 'printf' symbol, with the help of the dynamic linker, since the tool itself is linked to the (dynamic) C library. On windows (hence also on cygwin), the 'lli' tool fails to resolve the external symbol, since it is not exported from the '.exe'. The 'lli' tool can be used as an interpreter, so that the JIT compiler is disabled, which also side-steps this external symbol linking problem. Add the --[no-]jit options to the 'sparsei' tool, which in turn uses (or not) the '-force-interpreter' option to 'lli'. In order to fix the failing test-case, simply pass the '--no-jit' option to 'sparsei'. Signed-off-by: Ramsay Jones --- sparsei | 20 +++++++++++++++++++- validation/backend/sum.c | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sparsei b/sparsei index 3431a9f..3232200 100755 --- a/sparsei +++ b/sparsei @@ -2,6 +2,9 @@ set +e +SPARSEOPTS= +JIT_OPT= + DIRNAME=`dirname $0` LLI=`"${LLVM_CONFIG:-llvm-config}" --bindir`/lli @@ -10,4 +13,19 @@ if [ $# -eq 0 ]; then exit 1 fi -$DIRNAME/sparse-llvm $@ | $LLI +while [ $# -gt 0 ]; do + case $1 in + --jit) + JIT_OPT= + ;; + --no-jit) + JIT_OPT="-force-interpreter" + ;; + *) + SPARSEOPTS="$SPARSEOPTS $1 " + ;; + esac + shift +done + +$DIRNAME/sparse-llvm ${SPARSEOPTS} | $LLI ${JIT_OPT} diff --git a/validation/backend/sum.c b/validation/backend/sum.c index 0604299..fa51120 100644 --- a/validation/backend/sum.c +++ b/validation/backend/sum.c @@ -19,7 +19,7 @@ int main(int argc, char **argv) /* * check-name: sum from 1 to n - * check-command: sparsei $file + * check-command: sparsei --no-jit $file * * check-output-start 15 From patchwork Mon Nov 19 20:48:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689421 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 9653F14BD for ; Mon, 19 Nov 2018 20:48:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8431829FE4 for ; Mon, 19 Nov 2018 20:48:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 760A42A015; Mon, 19 Nov 2018 20:48:39 +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 1BD4929FE4 for ; Mon, 19 Nov 2018 20:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730825AbeKTHOB (ORCPT ); Tue, 20 Nov 2018 02:14:01 -0500 Received: from avasout04.plus.net ([212.159.14.19]:52482 "EHLO avasout04.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730824AbeKTHOB (ORCPT ); Tue, 20 Nov 2018 02:14:01 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqTEg9pO3Yyh2OqTFgYlx7; Mon, 19 Nov 2018 20:48:37 +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=xQA9DSoN0VXyDSm8IAQA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 3/9] pre-process: suppress trailing space when dumping macros Message-ID: <85a62d44-a351-4250-e88c-7efe0104b0f0@ramsayjones.plus.com> Date: Mon, 19 Nov 2018 20:48:35 +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: MS4wfAzvTg+BIHcObdeOdAobHkmseNySir34b8BoMFIW+hE8d/niI7V0NRHUE9QZcLljKpxjbVGJauWBkXsrimrTSWuLWdTWWbACxyALtJL4LNkLLZ2Gsruf pthTuTztuOYKZYc2szL7WL/eYTkfDHFITxTwFZP11pX5sUexNPMNnKFzK1cdpqoUUzAYka0rxPvuVA== 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 outputs a trailing space character for every macro. This makes comparing the '-dD' output from sparse to the similar output from gcc somewhat annoying. The space character arises from the presence of an token directly before the token in the macro definition token list. The token seems to always have the 'whitespace' flag set, which results in the output of a space in order to separate it from the current token. In order to suppress the unwanted space character, check if the next token is an token and, if so, don't print the space. Signed-off-by: Ramsay Jones --- pre-process.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pre-process.c b/pre-process.c index bf4b8e7..8abd5e6 100644 --- a/pre-process.c +++ b/pre-process.c @@ -2201,6 +2201,8 @@ static void dump_macro(struct symbol *sym) /* fall-through */ default: printf("%s", show_token(token)); + if (token_type(next) == TOKEN_UNTAINT) + break; if (next->pos.whitespace) putchar(' '); } 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 */ From patchwork Mon Nov 19 20:50:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689425 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 999A513AD for ; Mon, 19 Nov 2018 20:50:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B22E2A382 for ; Mon, 19 Nov 2018 20:50:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F88F2A3C8; Mon, 19 Nov 2018 20:50:41 +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 27A352A598 for ; Mon, 19 Nov 2018 20:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730827AbeKTHQD (ORCPT ); Tue, 20 Nov 2018 02:16:03 -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 S1730797AbeKTHQD (ORCPT ); Tue, 20 Nov 2018 02:16:03 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqVDg9pbcYyh2OqVEgYm3Y; Mon, 19 Nov 2018 20:50:40 +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=atKj8sqwZLVGDhMdaiMA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 5/9] pre-process: don't put spaces in macro parameter list Message-ID: <59e0760f-68af-099a-cb54-cbe4bad8cd54@ramsayjones.plus.com> Date: Mon, 19 Nov 2018 20:50:37 +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: MS4wfMsrqysUHaZgVGiWdCb90pUmxVdbR06RR95tisRPO3xTb7JDFl+kBVJxl6oKf5L1s0/CaW78T9NDX/Al+sC/HrTPW1GaJ4I4CLbaCE9yRzFPToNyLE2x lwrn310sr8ebS/7MYwWT8IPlZy2x6Igmlg/t+7oaDyGlMMjMKBwF0gge1wDtg1R2yNv1+KgTQS/eKw== 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 adds a ", " separator between the arguments of a function-like macro. Using a simple "," separator, which aligns the output with gcc, leads to one less distraction when comparing the output of sparse and gcc. Signed-off-by: Ramsay Jones --- pre-process.c | 2 +- validation/preprocessor/dump-macros.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pre-process.c b/pre-process.c index eca7ab5..7b76c65 100644 --- a/pre-process.c +++ b/pre-process.c @@ -2184,7 +2184,7 @@ static void dump_macro(struct symbol *sym) continue; printf("%s%s", sep, show_token(token)); args[narg++] = token; - sep = ", "; + sep = ","; } putchar(')'); } diff --git a/validation/preprocessor/dump-macros.c b/validation/preprocessor/dump-macros.c index 5a96464..f8983d8 100644 --- a/validation/preprocessor/dump-macros.c +++ b/validation/preprocessor/dump-macros.c @@ -19,5 +19,5 @@ 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 +check-output-contains: #define CONCAT(x,y) x ## y */ 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__) */ From patchwork Mon Nov 19 20:52: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: 10689429 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 B31A814BD for ; Mon, 19 Nov 2018 20:52:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A559E2A5E2 for ; Mon, 19 Nov 2018 20:52:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99E332A601; Mon, 19 Nov 2018 20:52:47 +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 1B5B12A5E2 for ; Mon, 19 Nov 2018 20:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730904AbeKTHSK (ORCPT ); Tue, 20 Nov 2018 02:18:10 -0500 Received: from avasout04.plus.net ([212.159.14.19]:52919 "EHLO avasout04.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730828AbeKTHSJ (ORCPT ); Tue, 20 Nov 2018 02:18:09 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqXDg9poIYyh2OqXEgYm8p; Mon, 19 Nov 2018 20:52:45 +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=t_2rAVzgGEZjFWMiDsEA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 7/9] pre-process: add the -dM option to dump macro definitions Message-ID: <2ee1506a-5e42-5736-5577-230e5f365fb5@ramsayjones.plus.com> Date: Mon, 19 Nov 2018 20:52: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: MS4wfGuG/x41Z94JG+gCgy7OjzYyxPAXg1e+i+UcgxjLZFqJrQcVRcKS4YFDi8gr8hnk6YiyHgJIqf7zhUrmz59clU07HpvzTKUZy+2L7G/PSs5V7KxMIwAc q4uzdVW6/tH38SMEmAVQKq9hZYulFgcCP5CG7Mz9d1aIkq3ofKVW7xSOgpkBOfz2IounsGTgFOmDow== 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 current -dD option outputs the macro definitions, in addition to the pre-processed text. In contrast, the -dM option outputs only the macro definitions. Signed-off-by: Ramsay Jones --- lib.c | 41 +++++++++++++++++----- lib.h | 1 + validation/preprocessor/dump-macros-only.c | 36 +++++++++++++++++++ validation/preprocessor/dump-macros.c | 6 ++++ 4 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 validation/preprocessor/dump-macros-only.c diff --git a/lib.c b/lib.c index 07a5b9c..23c3d27 100644 --- a/lib.c +++ b/lib.c @@ -287,6 +287,7 @@ int Wunknown_attribute = 0; int Wvla = 1; int dump_macro_defs = 0; +int dump_macros_only = 0; int dbg_compound = 0; int dbg_dead = 0; @@ -794,16 +795,34 @@ static char **handle_switch_v(char *arg, char **next) return next; } -static struct flag dumps[] = { - { "D", &dump_macro_defs}, -}; - static char **handle_switch_d(char *arg, char **next) { - char ** ret = handle_onoff_switch(arg, next, dumps, ARRAY_SIZE(dumps)); - if (ret) - return ret; + char *arg_char = arg + 1; + /* + * -d, where is a sequence of characters, not preceded + * by a space. If you specify characters whose behaviour conflicts, + * the result is undefined. + */ + while (*arg_char) { + switch (*arg_char) { + case 'M': /* dump just the macro definitions */ + dump_macros_only = 1; + dump_macro_defs = 0; + break; + case 'D': /* like 'M', but also output pre-processed text */ + dump_macro_defs = 1; + dump_macros_only = 0; + break; + case 'N': /* like 'D', but only output macro names not bodies */ + break; + case 'I': /* like 'D', but also output #include directives */ + break; + case 'U': /* like 'D', but only output expanded macros */ + break; + } + arg_char++; + } return next; } @@ -1311,8 +1330,12 @@ static struct symbol_list *sparse_tokenstream(struct token *token) // Preprocess the stream token = preprocess(token); - if (dump_macro_defs && !builtin) - dump_macro_definitions(); + if (dump_macro_defs || dump_macros_only) { + if (!builtin) + dump_macro_definitions(); + if (dump_macros_only) + return NULL; + } if (preprocess_only) { while (!eof_token(token)) { diff --git a/lib.h b/lib.h index cd1af9c..ae0e981 100644 --- a/lib.h +++ b/lib.h @@ -177,6 +177,7 @@ extern int Wunknown_attribute; extern int Wvla; extern int dump_macro_defs; +extern int dump_macros_only; extern int dbg_compound; extern int dbg_dead; diff --git a/validation/preprocessor/dump-macros-only.c b/validation/preprocessor/dump-macros-only.c new file mode 100644 index 0000000..cee6f87 --- /dev/null +++ b/validation/preprocessor/dump-macros-only.c @@ -0,0 +1,36 @@ + +#define ABC abc +#undef ABC + +#define DEF def +#undef DEF +#define DEF xyz + +#define NYDEF ydef + +#define STRING(x) #x +#define CONCAT(x,y) x ## y + +#define unlocks(...) annotate(unlock_func(__VA_ARGS__)) +#define apply(x,...) x(__VA_ARGS__) + +int main(int argc, char *argv[]) +{ + return 0; +} +/* + * check-name: dump-macros only -dM + * check-command: sparse -E -dM -DIJK=ijk -UNDEF -UNYDEF $file + * + * check-output-ignore +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 +check-output-contains: #define unlocks(...) annotate(unlock_func(__VA_ARGS__)) +check-output-contains: #define apply(x,...) x(__VA_ARGS__) +check-output-excludes: int main(int argc, char \\*argv\\[\\]) +check-output-excludes: ^\\[^#] + */ diff --git a/validation/preprocessor/dump-macros.c b/validation/preprocessor/dump-macros.c index 6940a20..dc2d7d1 100644 --- a/validation/preprocessor/dump-macros.c +++ b/validation/preprocessor/dump-macros.c @@ -12,6 +12,11 @@ #define unlocks(...) annotate(unlock_func(__VA_ARGS__)) #define apply(x,...) x(__VA_ARGS__) + +int main(int argc, char *argv[]) +{ + return 0; +} /* * check-name: dump-macros * check-command: sparse -E -dD -DIJK=ijk -UNDEF -UNYDEF $file @@ -25,4 +30,5 @@ 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__) +check-output-contains: int main(int argc, char \\*argv\\[\\]) */ From patchwork Mon Nov 19 20:53:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689431 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 9C90914BD for ; Mon, 19 Nov 2018 20:53:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E1FE29631 for ; Mon, 19 Nov 2018 20:53:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 827572A3F3; Mon, 19 Nov 2018 20:53:42 +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 179152A4B9 for ; Mon, 19 Nov 2018 20:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730838AbeKTHTF (ORCPT ); Tue, 20 Nov 2018 02:19:05 -0500 Received: from avasout04.plus.net ([212.159.14.19]:52919 "EHLO avasout04.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730828AbeKTHTF (ORCPT ); Tue, 20 Nov 2018 02:19:05 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqY7g9puZYyh2OqY9gYmBT; Mon, 19 Nov 2018 20:53:41 +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=acS-LPI_dNyR2nB0v8AA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 8/9] pre-processor: add some pre-defined macros Message-ID: Date: Mon, 19 Nov 2018 20:53:38 +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: MS4wfM75lHg7gesP8zrP80h1zf7n+3BV94Eaygh/UMHSQh3Alo+DgUZU3kiy/PU9GTKnvCCbUkqiObUwO4Jo3Ub7pDoPwPM2emkhHe8jLv/c1mcJVHKJI082 KUG9S3uO/ABEcPy/w2aIeLAFuR3HMDP++oZEzHFCvdpmXV+xbv+wxrzKSyduOxQbwEriofuV6a08ww== 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 Signed-off-by: Ramsay Jones --- lib.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/lib.c b/lib.c index 23c3d27..08dc299 100644 --- a/lib.c +++ b/lib.c @@ -46,6 +46,8 @@ #include "target.h" #include "version.h" +#define ULL_BITS (__CHAR_BIT__ * sizeof(unsigned long long)) + int verbose, optimize_level, optimize_size, preprocessing; int die_if_error = 0; int has_error = 0; @@ -1161,6 +1163,11 @@ static char **handle_switch(char *arg, char **next) return next; } +static void predefined_type(const char *name, const char *type_str) +{ + add_pre_buffer("#weak_define __%s_TYPE__ %s\n", name, type_str); +} + static void predefined_sizeof(const char *name, unsigned bits) { char buf[32]; @@ -1177,6 +1184,13 @@ static void predefined_width(const char *name, unsigned bits) predefine(buf, 1, "%d", bits); } +static void predefined_umax(const char *name, const char *suffix, unsigned bits) +{ + unsigned long long max = (~0ULL) >> (ULL_BITS - bits); + + add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix); +} + static void predefined_max(const char *name, const char *suffix, unsigned bits) { unsigned long long max = (1ULL << (bits - 1 )) - 1; @@ -1248,6 +1262,53 @@ static void predefined_macros(void) predefined_type_size("LONG", "L", bits_in_long); predefined_type_size("LONG_LONG", "LL", bits_in_longlong); + predefined_max("INT8", "", 8); + predefined_type("INT8", "signed char"); + predefined_max("INT16", "", 16); + predefined_type("INT16", "short int"); + predefined_max("INT32", "", 32); + predefined_type("INT32", "int"); + predefined_umax("UINT8", "", 8); + predefined_type("UINT8", "unsigned char"); + predefined_umax("UINT16", "", 16); + predefined_type("UINT16", "short unsigned int"); + predefined_umax("UINT32", "U", 32); + predefined_type("UINT32", "unsigned int"); + + if (bits_in_pointer == 64) { + predefined_max("INT64", "L", 64); + predefined_type("INT64", "long int"); + predefined_max("INTMAX", "L", 64); + predefined_type("INTMAX", "long int"); + predefined_max("INTPTR", "L", 64); + predefined_type("INTPTR", "long int"); + predefined_max("PTRDIFF", "L", 64); + predefined_type("PTRDIFF", "long int"); + predefined_umax("UINT64", "UL", 64); + predefined_type("UINT64", "long unsigned int"); + predefined_umax("UINTMAX", "UL", 64); + predefined_type("UINTMAX", "long unsigned int"); + predefined_umax("UINTPTR", "UL", 64); + predefined_type("UINTPTR", "long unsigned int"); + predefined_umax("SIZE", "UL", 64); + } else { + predefined_max("INT64", "LL", 64); + predefined_type("INT64", "long long int"); + predefined_max("INTMAX", "LL", 64); + predefined_type("INTMAX", "long long int"); + predefined_max("INTPTR", "", 32); + predefined_type("INTPTR", "int"); + predefined_max("PTRDIFF", "", 32); + predefined_type("PTRDIFF", "int"); + predefined_umax("UINT64", "ULL", 64); + predefined_type("UINT64", "long long unsigned int"); + predefined_umax("UINTMAX", "ULL", 64); + predefined_type("UINTMAX", "long long unsigned int"); + predefined_umax("UINTPTR", "U", 32); + predefined_type("UINTPTR", "unsigned int"); + predefined_umax("SIZE", "U", 32); + } + predefined_sizeof("INT128", 128); predefined_sizeof("SIZE_T", bits_in_pointer);