diff options
| author | Al Viro <viro@zeniv.linux.org.uk> | 2007-07-27 10:19:50 -0400 |
|---|---|---|
| committer | Josh Triplett <josh@freedesktop.org> | 2007-07-29 00:44:25 -0700 |
| commit | c716828bf2ba59af73f4eb058e6f131b1fb7d498 (patch) | |
| tree | f6f1ddc8db72d1cbf326b530484a3e7a34cc8c04 | |
| parent | 321ad07c0d299690e4a7b9e9386e1acf844f8404 (diff) | |
| download | sparse-dev-c716828bf2ba59af73f4eb058e6f131b1fb7d498.tar.gz | |
[PATCH] file and global scopes are the same for purposes of struct redefining
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
| -rw-r--r-- | parse.c | 2 | ||||
| -rw-r--r-- | scope.c | 10 | ||||
| -rw-r--r-- | scope.h | 1 | ||||
| -rw-r--r-- | validation/outer-scope.c | 19 |
4 files changed, 31 insertions, 1 deletions
@@ -481,7 +481,7 @@ static struct token *struct_union_enum_specifier(enum type type, if (token_type(token) == TOKEN_IDENT) { sym = lookup_symbol(token->ident, NS_STRUCT); if (!sym || - (sym->scope != block_scope && + (is_outer_scope(sym->scope) && (match_op(token->next,';') || match_op(token->next,'{')))) { // Either a new symbol, or else an out-of-scope // symbol being redefined. @@ -106,3 +106,13 @@ void end_function_scope(void) end_scope(&block_scope); end_scope(&function_scope); } + +int is_outer_scope(struct scope *scope) +{ + if (scope == block_scope) + return 0; + if (scope == &builtin_scope && block_scope->next == &builtin_scope) + return 0; + return 1; +} + @@ -38,4 +38,5 @@ extern void end_function_scope(void); extern void bind_scope(struct symbol *, struct scope *); +extern int is_outer_scope(struct scope *); #endif diff --git a/validation/outer-scope.c b/validation/outer-scope.c new file mode 100644 index 00000000..2ce05051 --- /dev/null +++ b/validation/outer-scope.c @@ -0,0 +1,19 @@ +#ifndef FOO +struct st { int len; }; +#define FOO +#else +struct st; +static int test(struct st *s); +static int test(struct st *s) +{ + return s->len; +} +#endif +/* + * check-name: There is no scope boundary between global and file scope + * check-description: Used to mess scopes with -include + * check-command: sparse -include $file $file + * + * check-output-start + * check-output-end + */ |
