From patchwork Sat Mar 21 17:28:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13539 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n2LHSZD8023821 for ; Sat, 21 Mar 2009 17:28:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754495AbZCUR2a (ORCPT ); Sat, 21 Mar 2009 13:28:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754739AbZCUR2a (ORCPT ); Sat, 21 Mar 2009 13:28:30 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:52526 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754495AbZCUR23 (ORCPT ); Sat, 21 Mar 2009 13:28:29 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.69 #1 (Red Hat Linux)) id 1Ll4zf-0001Ub-T3; Sat, 21 Mar 2009 17:28:23 +0000 Date: Sat, 21 Mar 2009 17:28:23 +0000 From: Al Viro To: Christopher Li Cc: Hannes Eder , linux-sparse@vger.kernel.org, Nicholas Mc Guire Subject: Re: [bug, bisected, -chrisl] Segfault at evaluate.c:341 Message-ID: <20090321172823.GA5509@ZenIV.linux.org.uk> References: <154e089b0903190649k7f099c93qedf6eb8e6a1c0a86@mail.gmail.com> <20090319144622.GA28946@ZenIV.linux.org.uk> <154e089b0903191138x15b66808v70bc862d7a13e3c2@mail.gmail.com> <20090319191431.GD28946@ZenIV.linux.org.uk> <70318cbf0903191304k1fefe9afkb4be21550d8f9abe@mail.gmail.com> <20090319215250.GF28946@ZenIV.linux.org.uk> <20090319220906.GG28946@ZenIV.linux.org.uk> <70318cbf0903191611i4ec1f5e5sa97ba53db3a7478c@mail.gmail.com> <20090321044020.GL28946@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090321044020.GL28946@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org 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 > --- It needed testing, all right - #elif handling got broken by the initial variant... Hopefully fixed version follows: --- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;