diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-26 23:09:21 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-26 23:09:21 +0100 |
commit | d06e1d291f581d14bfc78bc0c4b58c0b6e876c92 (patch) | |
tree | dc9b5020fc35907c21195fe76d9d4157f6f45da5 | |
parent | 172f6a98702de6eeef181fa72d07dfc78c5b40d1 (diff) | |
parent | 1546f48809a43f48769c374cc58a9a0b64ccda11 (diff) | |
download | sparse-d06e1d291f581d14bfc78bc0c4b58c0b6e876c92.tar.gz |
Merge branch 'static-forward' into master
-rw-r--r-- | symbol.c | 23 | ||||
-rw-r--r-- | validation/static-forward-decl.c | 19 |
2 files changed, 33 insertions, 9 deletions
@@ -627,6 +627,27 @@ void check_declaration(struct symbol *sym) } } +static void inherit_static(struct symbol *sym) +{ + struct symbol *prev; + + // only 'plain' symbols are concerned + if (sym->ctype.modifiers & (MOD_STATIC|MOD_EXTERN)) + return; + + for (prev = sym->next_id; prev; prev = prev->next_id) { + if (prev->namespace != NS_SYMBOL) + continue; + if (prev->scope != file_scope) + continue; + + sym->ctype.modifiers |= prev->ctype.modifiers & MOD_STATIC; + + // previous declarations are already converted + return; + } +} + void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) { struct scope *scope; @@ -650,6 +671,8 @@ void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) if (ns == NS_SYMBOL && toplevel(scope)) { unsigned mod = MOD_ADDRESSABLE | MOD_TOPLEVEL; + inherit_static(sym); + scope = global_scope; if (sym->ctype.modifiers & MOD_STATIC || is_extern_inline(sym)) { diff --git a/validation/static-forward-decl.c b/validation/static-forward-decl.c index daad1ecb..d25d8152 100644 --- a/validation/static-forward-decl.c +++ b/validation/static-forward-decl.c @@ -1,13 +1,14 @@ -static int f(void); +int fref(void); +int fref(void) { return 0; } + +static +int floc(void); +int floc(void) { return 0; } + +static +int oloc; +int oloc = 0; -int f(void) -{ - return 0; -} /* * check-name: static forward declaration - * - * check-error-start -static-forward-decl.c:3:5: warning: symbol 'f' was not declared. Should it be static? - * check-error-end */ |