aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--scope.c6
-rw-r--r--symbol.c10
2 files changed, 9 insertions, 7 deletions
diff --git a/scope.c b/scope.c
index 5305d03e..27b8b7c2 100644
--- a/scope.c
+++ b/scope.c
@@ -45,9 +45,9 @@ void start_file_scope(void)
scope->next = &builtin_scope;
file_scope = scope;
- /* top-level stuff defaults to global, "static" will choose file scope */
- function_scope = global_scope;
- block_scope = global_scope;
+ /* top-level stuff defaults to file scopt, "extern" etc will choose global scope */
+ function_scope = scope;
+ block_scope = scope;
}
void start_symbol_scope(void)
diff --git a/symbol.c b/symbol.c
index 898eab4a..42a282fd 100644
--- a/symbol.c
+++ b/symbol.c
@@ -463,11 +463,13 @@ void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns)
scope = block_scope;
if (ns == NS_SYMBOL && toplevel(scope)) {
- sym->ctype.modifiers |= MOD_TOPLEVEL;
- if (sym->ctype.modifiers & MOD_STATIC)
+ unsigned mod = MOD_ADDRESSABLE | MOD_TOPLEVEL;
+ scope = global_scope;
+ if (sym->ctype.modifiers & MOD_STATIC) {
scope = file_scope;
- else
- sym->ctype.modifiers |= MOD_ADDRESSABLE;
+ mod = MOD_TOPLEVEL;
+ }
+ sym->ctype.modifiers |= mod;
}
if (ns == NS_MACRO)
scope = file_scope;