linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
To: Christopher Li <sparse@chrisli.org>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: [PATCH 2/4] cgcc: avoid passing a sparse-only option to cc
Date: Sat, 11 Oct 2014 20:57:25 +0100	[thread overview]
Message-ID: <54398BA5.6050005@ramsay1.demon.co.uk> (raw)


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 <ramsay@ramsay1.demon.co.uk>
---

Hi Chris,

The following shows the error/fix:

    $ pwd
    /home/ramsay/sparse
    $ cat -n hello.c
         1	#include <stdio.h>
         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 <stdio.h>
         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;
 }
-- 
2.1.0
--
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

             reply	other threads:[~2014-10-11 19:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-11 19:57 Ramsay Jones [this message]
2014-10-15 14:23 ` [PATCH 2/4] cgcc: avoid passing a sparse-only option to cc Christopher Li
2014-10-15 17:33   ` Ramsay Jones
2014-10-16  1:45     ` Christopher Li
2014-10-19 14:21       ` Ramsay Jones
2014-10-22  0:23         ` Christopher Li
2014-10-23  0:38           ` Ramsay Jones
2014-10-25  4:14             ` Christopher Li
2014-10-25 12:32               ` Ramsay Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54398BA5.6050005@ramsay1.demon.co.uk \
    --to=ramsay@ramsay1.demon.co.uk \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).