From: "Darren Jenkins\\" <darrenrjenkins@gmail.com>
To: Sparse mailing list <linux-sparse@vger.kernel.org>
Subject: Sparse RFC
Date: Mon, 26 Mar 2007 23:29:35 +1000 [thread overview]
Message-ID: <1174915776.1142.21.camel@localhost.localdomain> (raw)
G'day people,
I have been playing around with the sparse code, and was thinking of
adding a few of the checks that my company uses from other code
checkers, starting with checking that macro arguments have brackets
around them. (Because this is the test my/other code most often fails)
I have put together a quick patch to see what everyone thinks of it. It
is obviously not a finished product but I wanted to see peoples
reactions to this type of thing.
I also have a few questions;
1) Do we want to add a Wdescription switch for each test sparse
performs ? or do we want to group tests under Wstyle Wefficiency
WCodingStandard type group switches ?
2) For the macro argument checking would it be better if I checked for
either a bracket or low precedence operator on both sides of the
argument ? like either a comma or a type of assignment operator? it
would not be a foolproof check then but would seem more sensible to me,
and might be more acceptable to users.
Anyway here is the patch
diff --git a/lib.c b/lib.c
index 79a5c55..27c9fe1 100644
--- a/lib.c
+++ b/lib.c
@@ -204,6 +204,7 @@ int Waddress_space = 1;
int Wenum_mismatch = 1;
int Wdo_while = 1;
int Wuninitialized = 1;
+int Wmacro_argument_brackets = 1;
int dbg_entry = 0;
int dbg_dead = 0;
diff --git a/lib.h b/lib.h
index 472624d..2657ce3 100644
--- a/lib.h
+++ b/lib.h
@@ -98,6 +98,7 @@ extern int Wshadow;
extern int Wcast_truncate;
extern int Wdo_while;
extern int Wuninitialized;
+extern int Wmacro_argument_brackets;
extern int dbg_entry;
extern int dbg_dead;
diff --git a/pre-process.c b/pre-process.c
index afae77a..a04a157 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -1034,7 +1034,9 @@ static struct token *parse_expansion(str
} else if (match_op(token->next, SPECIAL_HASHHASH)) {
try_arg(token, TOKEN_QUOTED_ARGUMENT, arglist);
} else {
- try_arg(token, TOKEN_MACRO_ARGUMENT, arglist);
+ int argument = try_arg(token, TOKEN_MACRO_ARGUMENT, arglist);
+ if (argument == 1 && Wmacro_argument_brackets && (!match_op(token->next, ')') || !match_op(last, '(')) )
+ warning(token->pos, "Macro argument is not bracketed in expansion");
}
if (token_type(token) == TOKEN_ERROR)
goto Earg;
diff --git a/token.h b/token.h
diff --git a/tokenize.c b/tokenize.c
next reply other threads:[~2007-03-26 13:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-26 13:29 Darren Jenkins\ [this message]
2007-03-26 16:15 ` Sparse RFC Derek M Jones
2007-03-26 21:21 ` Linus Torvalds
2007-03-27 3:07 ` Darren Jenkins
2007-03-27 12:04 ` Uwe Kleine-König
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=1174915776.1142.21.camel@localhost.localdomain \
--to=darrenrjenkins@gmail.com \
--cc=linux-sparse@vger.kernel.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).