From: Oleg Nesterov <oleg@tv-sign.ru>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux-sparse@vger.kernel.org, Josh Triplett <josht@us.ibm.com>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 4/4] fix loss of 'weak' attribute on usage
Date: Mon, 4 Sep 2006 19:42:11 +0400 [thread overview]
Message-ID: <20060904154211.GA6437@oleg> (raw)
When NS_MACRO symbol is used, sparse clears it's 'weak' flag.
This is bad for multifile parsing, and wrong:
#weak_define FOO 1
FOO
#weak_define FOO 2 // silently ignored
After this patch sparse never writes to NS_MACRO symbols from
another scope.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
--- git-snapshot-20060904/symbol.h~4USED 2006-09-04 18:20:23.000000000 +0400
+++ git-snapshot-20060904/symbol.h 2006-09-04 19:22:36.000000000 +0400
@@ -97,6 +97,7 @@ struct symbol {
struct /* NS_MACRO */ {
struct token *expansion;
struct token *arglist;
+ struct scope *used_in;
};
struct /* NS_PREPROCESSOR */ {
int (*handler)(struct stream *, struct token **, struct token *);
--- git-snapshot-20060904/pre-process.c~4USED 2006-09-04 19:17:22.000000000 +0400
+++ git-snapshot-20060904/pre-process.c 2006-09-04 19:22:36.000000000 +0400
@@ -114,7 +114,7 @@ static int token_defined(struct token *t
if (token_type(token) == TOKEN_IDENT) {
struct symbol *sym = lookup_macro(token->ident);
if (sym) {
- sym->weak = 0;
+ sym->used_in = file_scope;
return 1;
}
return 0;
@@ -143,7 +143,7 @@ static int expand_one_symbol(struct toke
sym = lookup_macro(token->ident);
if (sym) {
- sym->weak = 0;
+ sym->used_in = file_scope;
return expand(list, sym);
}
if (token->ident == &__LINE___ident) {
@@ -1096,7 +1096,7 @@ static int do_handle_define(struct strea
if (token_list_different(sym->expansion, expansion) ||
token_list_different(sym->arglist, arglist)) {
ret = 0;
- if (clean && !weak) {
+ if ((clean && !weak) || sym->used_in == file_scope) {
warning(left->pos, "preprocessor token %.*s redefined",
name->len, name->name);
info(sym->pos, "this was the original definition");
@@ -1117,6 +1117,7 @@ static int do_handle_define(struct strea
__free_token(token); /* Free the "define" token, but not the rest of the line */
}
+ sym->used_in = NULL;
sym->weak = weak;
out:
return ret;
@@ -1152,6 +1153,7 @@ static int handle_undef(struct stream *s
}
sym->namespace = NS_UNDEF;
+ sym->used_in = NULL;
return 1;
}
--
VGER BF report: U 0.500211
reply other threads:[~2006-09-04 11:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20060904154211.GA6437@oleg \
--to=oleg@tv-sign.ru \
--cc=josht@us.ibm.com \
--cc=linux-sparse@vger.kernel.org \
--cc=torvalds@osdl.org \
--cc=viro@zeniv.linux.org.uk \
/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