From: Oleg Nesterov <oleg@redhat.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Alexey Gladkov <gladkov.alexey@gmail.com>, linux-sparse@vger.kernel.org
Subject: [PATCH v2 1/2] struct_union_enum_specifier: always initialize sym->scope
Date: Wed, 19 Feb 2020 17:29:11 +0100 [thread overview]
Message-ID: <20200219162911.GA26790@redhat.com> (raw)
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 <oleg@redhat.com>
---
parse.c | 2 ++
scope.c | 5 +++++
scope.h | 1 +
3 files changed, 8 insertions(+)
diff --git a/parse.c b/parse.c
index a08165a..3e7c60e 100644
--- a/parse.c
+++ b/parse.c
@@ -772,6 +772,8 @@ static struct token *struct_union_enum_specifier(enum type type,
}
sym = alloc_symbol(token->pos, type);
+ /* make toplevel(sym->scope) work */
+ set_current_scope(sym);
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 cbf2fcf..420c0f5 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 d9a14aa..3cad514 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 *);
--
2.5.0
next reply other threads:[~2020-02-19 16:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-19 16:29 Oleg Nesterov [this message]
2020-02-19 16:29 ` [PATCH v2 2/2] dissect: fix sym_is_local(SYM_STRUCT/UNION/ENUM) Oleg Nesterov
2020-02-20 0:56 ` [PATCH v2 1/2] struct_union_enum_specifier: always initialize sym->scope Luc Van Oostenryck
2020-02-20 11:57 ` Oleg Nesterov
2020-02-20 12:15 ` Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200219162911.GA26790@redhat.com \
--to=oleg@redhat.com \
--cc=gladkov.alexey@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).