linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Christopher Li" <sparse@chrisli.org>
To: Linux-Sparse <linux-sparse@vger.kernel.org>,
	Josh Triplett <josh@freedesktop.org>
Subject: [PATCH] allow ifdef in macro arguments
Date: Sun, 21 Oct 2007 02:07:15 -0700	[thread overview]
Message-ID: <70318cbf0710210207t587f8d2enf024a56e1d10a5df@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 49 bytes --]

I think some one report it long time ago.

Chris

[-- Attachment #2: ifdef-macro-arg --]
[-- Type: application/octet-stream, Size: 2238 bytes --]

Allow #ifdef in macro arguments

As the case shows. Sparse does not handle pre-process in
macro arguments.

This patch allow the pre-process can happen in macro arguments.

Signed-Off-By: Christopher Li <sparse@chrisli.org>

Index: sparse/pre-process.c
===================================================================
--- sparse.orig/pre-process.c	2007-10-21 00:56:37.000000000 -0700
+++ sparse/pre-process.c	2007-10-21 01:57:01.000000000 -0700
@@ -83,6 +83,7 @@ static struct token *alloc_token(struct 
 }
 
 static const char *show_token_sequence(struct token *token);
+static inline struct token *next_preprocess_token(struct token **list);
 
 /* Expand symbol 'sym' at '*list' */
 static int expand(struct token **, struct symbol *);
@@ -199,7 +200,7 @@ static struct token *collect_arg(struct 
 	struct token *next;
 	int nesting = 0;
 
-	while (!eof_token(next = scan_next(p))) {
+	while ((next = next_preprocess_token(p))) {
 		if (match_op(next, '(')) {
 			nesting++;
 		} else if (match_op(next, ')')) {
@@ -1702,7 +1703,7 @@ static void preprocessor_line(struct str
 	handle_preprocessor_line(stream, line, start);
 }
 
-static void do_preprocess(struct token **list)
+static inline struct token *next_preprocess_token(struct token **list)
 {
 	struct token *next;
 
@@ -1740,11 +1741,22 @@ static void do_preprocess(struct token *
 				__free_token(next);
 				continue;
 			}
-
-			if (token_type(next) != TOKEN_IDENT ||
-			    expand_one_symbol(list))
-				list = &next->next;
 		}
+		return next;
+	}
+
+	return NULL;
+}
+
+
+static void do_preprocess(struct token **list)
+{
+	struct token *next;
+
+	while ((next = next_preprocess_token(list))) {
+		if (token_type(next) != TOKEN_IDENT ||
+		    expand_one_symbol(list))
+			list = &next->next;
 	}
 }
 
Index: sparse/validation/macro-argument-ifdef.c
===================================================================
--- sparse.orig/validation/macro-argument-ifdef.c	2007-10-21 01:57:01.000000000 -0700
+++ sparse/validation/macro-argument-ifdef.c	2007-10-21 01:57:01.000000000 -0700
@@ -0,0 +1,17 @@
+#define foo(a,b,c) bar(a,b,c)
+
+static void bar(int a, int b, int c)
+{
+}
+
+static void test(void)
+{
+	foo(1,
+#ifdef NOT
+	2,
+#else
+	3,
+#endif
+	4);
+}
+

             reply	other threads:[~2007-10-21  9:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-21  9:07 Christopher Li [this message]
2007-10-21  9:18 ` [PATCH] allow ifdef in macro arguments Ralf Wildenhues
2007-10-21 15:52 ` Al Viro
2007-10-22  0:03   ` Josh Triplett
2007-10-22 16:13     ` Christopher Li

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=70318cbf0710210207t587f8d2enf024a56e1d10a5df@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=josh@freedesktop.org \
    --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).