aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@tv-sign.ru>2006-01-02 22:20:12 +0300
committerJosh Triplett <josh@freedesktop.org>2006-12-05 03:04:36 -0800
commit7207be8d9e4de12b91e8b7f4a5a82019a5c48744 (patch)
tree8a3a67e0089eb70499ac4381d314ab11c2d8d184 /pre-process.c
parentfix redefine of #weak_define (diff)
downloadsparse-7207be8d9e4de12b91e8b7f4a5a82019a5c48744.tar.gz
sparse-7207be8d9e4de12b91e8b7f4a5a82019a5c48744.tar.bz2
sparse-7207be8d9e4de12b91e8b7f4a5a82019a5c48744.zip
fix 'weak' attribute loss
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 (except ->used_in). Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Diffstat (limited to 'pre-process.c')
-rw-r--r--pre-process.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/pre-process.c b/pre-process.c
index 6f3145f..63f83db 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -118,7 +118,7 @@ static int token_defined(struct token *token)
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;
@@ -147,7 +147,7 @@ static int expand_one_symbol(struct token **list)
sym = lookup_macro(token->ident);
if (sym) {
- sym->weak = 0;
+ sym->used_in = file_scope;
return expand(list, sym);
}
if (token->ident == &__LINE___ident) {
@@ -1100,7 +1100,7 @@ static int do_handle_define(struct stream *stream, struct token **line, struct t
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");
@@ -1121,6 +1121,7 @@ static int do_handle_define(struct stream *stream, struct token **line, struct t
__free_token(token); /* Free the "define" token, but not the rest of the line */
}
+ sym->used_in = NULL;
sym->weak = weak;
out:
return ret;
@@ -1156,6 +1157,7 @@ static int handle_undef(struct stream *stream, struct token **line, struct token
}
sym->namespace = NS_UNDEF;
+ sym->used_in = NULL;
return 1;
}