From patchwork Sat Oct 11 19:57:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 5069741 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 31E9A9F295 for ; Sat, 11 Oct 2014 19:57:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27EF02017D for ; Sat, 11 Oct 2014 19:57:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48A9320160 for ; Sat, 11 Oct 2014 19:57:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751582AbaJKT53 (ORCPT ); Sat, 11 Oct 2014 15:57:29 -0400 Received: from mdfmta004.mxout.tch.inty.net ([91.221.169.45]:46235 "EHLO smtp.demon.co.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751006AbaJKT52 (ORCPT ); Sat, 11 Oct 2014 15:57:28 -0400 Received: from mdfmta004.tch.inty.net (unknown [127.0.0.1]) by mdfmta004.tch.inty.net (Postfix) with ESMTP id 55863AC40ED; Sat, 11 Oct 2014 20:57:27 +0100 (BST) Received: from mdfmta004.tch.inty.net (unknown [127.0.0.1]) by mdfmta004.tch.inty.net (Postfix) with ESMTP id F30BAAC40D6; Sat, 11 Oct 2014 20:57:26 +0100 (BST) Received: from [10.0.2.15] (unknown [80.176.147.220]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mdfmta004.tch.inty.net (Postfix) with ESMTP; Sat, 11 Oct 2014 20:57:26 +0100 (BST) Message-ID: <54398BA5.6050005@ramsay1.demon.co.uk> Date: Sat, 11 Oct 2014 20:57:25 +0100 From: Ramsay Jones User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: Christopher Li CC: Sparse Mailing-list Subject: [PATCH 2/4] cgcc: avoid passing a sparse-only option to cc X-MDF-HostID: 17 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Passing the '-Wsparse-error' to cgcc can cause that option to be passed to the C compiler (usually gcc), if the given source file does not provoke any sparse warnings, which in turn results in a failure to compile that file. In order to avoid passing this sparse option to the compiler, we add the '-Wsparse-error' option to the regular expression check in the 'check_only_option' function. In addition, we replace the plain call to 'die' when sparse exits with non-zero status (maybe due to -Wsparse-error), with a simple 'exit 1'. This suppresses an 'Died at ./cgcc line 86.' message on exit from cgcc. Signed-off-by: Ramsay Jones --- Hi Chris, The following shows the error/fix: $ pwd /home/ramsay/sparse $ cat -n hello.c 1 #include 2 3 int main(void) 4 { 5 printf("Hello, world!\n"); 6 return 0; 7 } $ CHECK=./sparse ./cgcc hello.c $ echo $? 0 $ CHECK=./sparse ./cgcc -Wsparse-error hello.c cc: error: unrecognized command line option ‘-Wsparse-error’ $ echo $? 1 $ Note gcc complaining about the unknown option. Now edit hello.c so that we generate a sparse warning ... $ cat -n hello.c 1 #include 2 3 int f(void) 4 { 5 return 42; 6 } 7 8 int main(void) 9 { 10 printf("Hello, world!\n"); 11 return 0; 12 } $ CHECK=./sparse ./cgcc hello.c hello.c:3:5: warning: symbol 'f' was not declared. Should it be static? $ echo $? 0 $ CHECK=./sparse ./cgcc -Wsparse-error hello.c hello.c:3:5: error: symbol 'f' was not declared. Should it be static? Died at ./cgcc line 86. $ echo $? 1 $ After this patch: with the original hello.c ... $ CHECK=./sparse ./cgcc hello.c $ echo $? 0 $ CHECK=./sparse ./cgcc -Wsparse-error hello.c $ echo $? 0 $ with the modified hello.c ... $ CHECK=./sparse ./cgcc hello.c hello.c:3:5: warning: symbol 'f' was not declared. Should it be static? $ echo $? 0 $ CHECK=./sparse ./cgcc -Wsparse-error hello.c hello.c:3:5: error: symbol 'f' was not declared. Should it be static? $ echo $? 1 $ ATB, Ramsay Jones cgcc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cgcc b/cgcc index 8ee8da1..8e38174 100755 --- a/cgcc +++ b/cgcc @@ -83,7 +83,7 @@ if ($do_check) { print "$check\n" if $verbose; if ($do_compile) { - system ($check) == 0 or die; + system ($check) == 0 or exit 1; } else { exec ($check); } @@ -101,7 +101,7 @@ exit 0; sub check_only_option { my ($arg) = @_; - return 1 if $arg =~ /^-W(no-?)?(default-bitfield-sign|one-bit-signed-bitfield|cast-truncate|bitwise|typesign|context|undef|ptr-subtraction-blows|cast-to-as|decl|transparent-union|address-space|enum-mismatch|do-while|old-initializer|non-pointer-null|paren-string|return-void|designated-init|sparse-all)$/; + return 1 if $arg =~ /^-W(no-?)?(default-bitfield-sign|one-bit-signed-bitfield|cast-truncate|bitwise|typesign|context|undef|ptr-subtraction-blows|cast-to-as|decl|transparent-union|address-space|enum-mismatch|do-while|old-initializer|non-pointer-null|paren-string|return-void|designated-init|sparse-all|sparse-error)$/; return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/; return 0; }