linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] allow ifdef in macro arguments
@ 2007-10-21  9:07 Christopher Li
  2007-10-21  9:18 ` Ralf Wildenhues
  2007-10-21 15:52 ` Al Viro
  0 siblings, 2 replies; 5+ messages in thread
From: Christopher Li @ 2007-10-21  9:07 UTC (permalink / raw)
  To: Linux-Sparse, Josh Triplett

[-- 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);
+}
+

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-10-22 16:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-21  9:07 [PATCH] allow ifdef in macro arguments Christopher Li
2007-10-21  9:18 ` Ralf Wildenhues
2007-10-21 15:52 ` Al Viro
2007-10-22  0:03   ` Josh Triplett
2007-10-22 16:13     ` Christopher Li

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).