From 7207be8d9e4de12b91e8b7f4a5a82019a5c48744 Mon Sep 17 00:00:00 2001 From: Oleg Nesterov Date: Mon, 2 Jan 2006 22:20:12 +0300 Subject: [PATCH] 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 --- pre-process.c | 8 +++++--- symbol.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pre-process.c b/pre-process.c index 6f3145f8..63f83dbb 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; } diff --git a/symbol.h b/symbol.h index e3b6b450..498e6e35 100644 --- a/symbol.h +++ b/symbol.h @@ -99,6 +99,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 *); -- 2.11.4.GIT