* [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
* Re: [PATCH] allow ifdef in macro arguments
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
1 sibling, 0 replies; 5+ messages in thread
From: Ralf Wildenhues @ 2007-10-21 9:18 UTC (permalink / raw)
To: Christopher Li; +Cc: Linux-Sparse, Josh Triplett
Hello Christopher,
* Christopher Li wrote on Sun, Oct 21, 2007 at 11:07:15AM CEST:
> I think some one report it long time ago.
FWIW, embedding directives within macro arguments is not portable
(warned by with gcc -pedantic), and causes undefined behavior according
to C99:6.10.3p11.
Cheers,
Ralf
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] allow ifdef in macro arguments
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
1 sibling, 1 reply; 5+ messages in thread
From: Al Viro @ 2007-10-21 15:52 UTC (permalink / raw)
To: Christopher Li; +Cc: Linux-Sparse, Josh Triplett
On Sun, Oct 21, 2007 at 02:07:15AM -0700, Christopher Li wrote:
> I think some one report it long time ago.
It should not accept those. Undefined behaviour and if you try to actually
define the semantics for it, you run into such a pile of corner cases that
it's not worth even trying.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] allow ifdef in macro arguments
2007-10-21 15:52 ` Al Viro
@ 2007-10-22 0:03 ` Josh Triplett
2007-10-22 16:13 ` Christopher Li
0 siblings, 1 reply; 5+ messages in thread
From: Josh Triplett @ 2007-10-22 0:03 UTC (permalink / raw)
To: Al Viro; +Cc: Christopher Li, Linux-Sparse
[-- Attachment #1: Type: text/plain, Size: 640 bytes --]
Al Viro wrote:
> On Sun, Oct 21, 2007 at 02:07:15AM -0700, Christopher Li wrote:
>> I think some one report it long time ago.
>
> It should not accept those. Undefined behaviour and if you try to actually
> define the semantics for it, you run into such a pile of corner cases that
> it's not worth even trying.
Do you think the cases handled by GCC warrant making an attempt and
warning about it, or should Sparse just throw up its hands and give
up?
If the latter, should Sparse make any attempt at all to detect
preprocessor conditionals in macro arguments so it can give a more
specific warning?
- Josh Triplett
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] allow ifdef in macro arguments
2007-10-22 0:03 ` Josh Triplett
@ 2007-10-22 16:13 ` Christopher Li
0 siblings, 0 replies; 5+ messages in thread
From: Christopher Li @ 2007-10-22 16:13 UTC (permalink / raw)
To: Josh Triplett; +Cc: Al Viro, Linux-Sparse
I want to know the answer too so I can try a different patch
or just forget about it.
Chris
On 10/21/07, Josh Triplett <josh@freedesktop.org> wrote:
> Al Viro wrote:
> > On Sun, Oct 21, 2007 at 02:07:15AM -0700, Christopher Li wrote:
> >> I think some one report it long time ago.
> >
> > It should not accept those. Undefined behaviour and if you try to actually
> > define the semantics for it, you run into such a pile of corner cases that
> > it's not worth even trying.
>
> Do you think the cases handled by GCC warrant making an attempt and
> warning about it, or should Sparse just throw up its hands and give
> up?
>
> If the latter, should Sparse make any attempt at all to detect
> preprocessor conditionals in macro arguments so it can give a more
> specific warning?
>
> - Josh Triplett
>
>
>
^ 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).