linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Christopher Li <sparse@chrisli.org>
Cc: Hannes Eder <hannes@hanneseder.net>,
	linux-sparse@vger.kernel.org,
	Nicholas Mc Guire <der.herr@hofr.at>
Subject: Re: [bug, bisected, -chrisl] Segfault at evaluate.c:341
Date: Sat, 21 Mar 2009 17:28:23 +0000	[thread overview]
Message-ID: <20090321172823.GA5509@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20090321044020.GL28946@ZenIV.linux.org.uk>

On Sat, Mar 21, 2009 at 04:40:20AM +0000, Al Viro wrote:
> On Thu, Mar 19, 2009 at 04:11:41PM -0700, Christopher Li wrote:
> > Thanks Al,
> > 
> > I will apply it later tonight.
> > 
> > If no one beats to me, I will try to add the warning for using preprocessor
> > directive inside macro expansion. It should be a better error message
> > than the current one.
> 
> Well...  patch below would give more or less close approximation to the
> current set of nasal demons produced by gcc in these situations + error
> when that crap happens.
> Warning: it might make things slower, and it needs testing.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---

It needed testing, all right - #elif handling got broken by the initial
variant...  Hopefully fixed version follows:

diff --git a/pre-process.c b/pre-process.c
index cf53893..34b21ff 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -193,13 +193,36 @@ static void expand_list(struct token **list)
 	}
 }
 
+static void preprocessor_line(struct stream *stream, struct token **line);
+
 static struct token *collect_arg(struct token *prev, int vararg, struct position *pos)
 {
+	struct stream *stream = input_streams + prev->pos.stream;
 	struct token **p = &prev->next;
 	struct token *next;
 	int nesting = 0;
 
 	while (!eof_token(next = scan_next(p))) {
+		if (next->pos.newline && match_op(next, '#')) {
+			if (!next->pos.noexpand) {
+				sparse_error(next->pos,
+					     "directive in argument list");
+				preprocessor_line(stream, p);
+				__free_token(next);	/* Free the '#' token */
+				continue;
+			}
+		}
+		switch (token_type(next)) {
+		case TOKEN_STREAMEND:
+		case TOKEN_STREAMBEGIN:
+			*p = &eof_token_entry;
+			return next;
+		}
+		if (false_nesting) {
+			*p = next->next;
+			__free_token(next);
+			continue;
+		}
 		if (match_op(next, '(')) {
 			nesting++;
 		} else if (match_op(next, ')')) {
@@ -1357,8 +1380,9 @@ static int handle_elif(struct stream * stream, struct token **line, struct token
 	if (token_type(top_if) != TOKEN_IF)
 		return 1;
 	if (false_nesting) {
-		if (expression_value(&token->next))
-			false_nesting = 0;
+		false_nesting = 0;
+		if (!expression_value(&token->next))
+			false_nesting = 1;
 	} else {
 		false_nesting = 1;
 		token_type(top_if) = TOKEN_SKIP_GROUPS;

  reply	other threads:[~2009-03-21 17:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19 13:49 [bug, bisected, -chrisl] Segfault at evaluate.c:341 Hannes Eder
2009-03-19 14:46 ` Al Viro
2009-03-19 18:32   ` Nicholas Mc Guire
2009-03-19 18:38   ` Hannes Eder
2009-03-19 19:14     ` Al Viro
2009-03-19 20:04       ` Christopher Li
2009-03-19 21:52         ` Al Viro
2009-03-19 22:09           ` Al Viro
2009-03-19 23:11             ` Christopher Li
2009-03-21  4:40               ` Al Viro
2009-03-21 17:28                 ` Al Viro [this message]
2009-03-23  9:22                   ` 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=20090321172823.GA5509@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=der.herr@hofr.at \
    --cc=hannes@hanneseder.net \
    --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).