From 9ac20e9e3c06918665aada812b0452d88d835291 Mon Sep 17 00:00:00 2001 From: Oleg Nesterov Date: Wed, 19 Feb 2020 17:29:11 +0100 Subject: struct_union_enum_specifier: always initialize sym->scope Currently it is not possible to figure out the scope of the private struct/union/enum type, its ->scope is NULL because bind_symbol() is not called. Change struct_union_enum_specifier() to set sym->scope = block_scope in this case, this is what bind_symbol() does when type has a name. Signed-off-by: Oleg Nesterov Signed-off-by: Luc Van Oostenryck --- parse.c | 1 + scope.c | 5 +++++ scope.h | 1 + 3 files changed, 7 insertions(+) diff --git a/parse.c b/parse.c index fb05253b..0e6f66a8 100644 --- a/parse.c +++ b/parse.c @@ -772,6 +772,7 @@ static struct token *struct_union_enum_specifier(enum type type, } sym = alloc_symbol(token->pos, type); + set_current_scope(sym); // used by dissect token = parse(token->next, sym); ctx->ctype.base_type = sym; token = expect(token, '}', "at end of specifier"); diff --git a/scope.c b/scope.c index cbf2fcf5..420c0f5a 100644 --- a/scope.c +++ b/scope.c @@ -40,6 +40,11 @@ struct scope *block_scope = &builtin_scope, // regular automatic variables etc *file_scope = &builtin_scope, // static *global_scope = &builtin_scope; // externally visible +void set_current_scope(struct symbol *sym) +{ + sym->scope = block_scope; +} + void bind_scope(struct symbol *sym, struct scope *scope) { sym->scope = scope; diff --git a/scope.h b/scope.h index d9a14aa3..3cad514a 100644 --- a/scope.h +++ b/scope.h @@ -53,6 +53,7 @@ extern void end_symbol_scope(void); extern void start_function_scope(void); extern void end_function_scope(void); +extern void set_current_scope(struct symbol *); extern void bind_scope(struct symbol *, struct scope *); extern void rebind_scope(struct symbol *, struct scope *); -- cgit 1.2.3-korg