From: Linus Torvalds <torvalds@linux-foundation.org>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH 15/17] scope: give a scope for labels & gotos
Date: Tue, 14 Apr 2020 11:19:32 -0700 [thread overview]
Message-ID: <CAHk-=wiahqumRaQkkcQ_kFhknA9z==DCWNKK-j0GRJH7GUtPEw@mail.gmail.com> (raw)
In-Reply-To: <20200414074934.urvzzgpi2a36jdf2@ltop.local>
[-- Attachment #1: Type: text/plain, Size: 827 bytes --]
On Tue, Apr 14, 2020 at 12:49 AM Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
>
> The problem is that now normal labels use the new label_scope
> but the ones declared with __label__ use block_scope and these
> 2 scopes are kinda in a different namespace of scope.
Oh, I forgot about the special __label__ thing that actually declares labels.
That one has an interesting behavior, in that the _lifetime_ of the
symbol is the block scope, but the *use* of the symbol must remain in
label scope.
The most obvious fix is probably something like the appended: make the
'sym->scope' remain the lifetime scope, but then attach a "must be
used in this scope' thing to any NS_LABEL case.
That fairly clearly separates the two issues.
Again, not actually tested outside of the obvious trivial case.
Linus
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 2503 bytes --]
parse.c | 16 +++++++++++-----
scope.c | 1 +
symbol.h | 3 +++
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/parse.c b/parse.c
index 8e238f59..b6109516 100644
--- a/parse.c
+++ b/parse.c
@@ -728,6 +728,7 @@ struct symbol *label_symbol(struct token *token)
if (!sym) {
sym = alloc_symbol(token->pos, SYM_LABEL);
bind_symbol(sym, token->ident, NS_LABEL);
+ sym->declared_scope = label_scope;
fn_local_symbol(sym);
}
return sym;
@@ -2541,13 +2542,14 @@ static struct token *statement(struct token *token, struct statement **tree)
}
/*
* If the scope of the label symbol is different
- * from the current label scope, that means that
- * it must have been used at an outer scope.
+ * from the declared label scope, that means that
+ * it must have been used or declared at an outer
+ * scope.
*
* That's not ok.
*/
- if (s->scope != label_scope) {
- sparse_error(stmt->pos, "label '%s' used outside label expression", show_ident(s->ident));
+ if (s->scope != s->declared_scope) {
+ sparse_error(stmt->pos, "label '%s' used outside statement expression", show_ident(s->ident));
sparse_error(s->pos, "invalid use here");
}
stmt->type = STMT_LABEL;
@@ -2575,9 +2577,13 @@ static struct token *label_statement(struct token *token)
{
while (token_type(token) == TOKEN_IDENT) {
struct symbol *sym = alloc_symbol(token->pos, SYM_LABEL);
- /* it's block-scope, but we want label namespace */
+
+ /* it's lifetile is block-scope, but we want label namespace */
bind_symbol(sym, token->ident, NS_SYMBOL);
sym->namespace = NS_LABEL;
+
+ /* But we must define it in this label scope */
+ sym->declared_scope = label_scope;
fn_local_symbol(sym);
token = token->next;
if (!match_op(token, ','))
diff --git a/scope.c b/scope.c
index 4b0f7947..11792ec4 100644
--- a/scope.c
+++ b/scope.c
@@ -171,6 +171,7 @@ void end_label_scope(void)
/* Re-bind the symbol to the parent scope, we'll try again */
bind_scope(sym, label_scope);
+ sym->declared_scope = label_scope;
} END_FOR_EACH_PTR(sym);
end_scope(&block_scope);
diff --git a/symbol.h b/symbol.h
index 18476582..08e35438 100644
--- a/symbol.h
+++ b/symbol.h
@@ -167,6 +167,9 @@ struct symbol {
int (*handler)(struct stream *, struct token **, struct token *);
int normal;
};
+ struct /* NS_LABEL */ {
+ struct scope *declared_scope;
+ };
struct /* NS_SYMBOL */ {
unsigned long offset;
int bit_size;
next prev parent reply other threads:[~2020-04-14 18:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-13 16:15 [PATCH 00/17] detect invalid branches at evaluation time Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 01/17] bad-goto: add testcase for 'jump inside discarded expression statement' Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 02/17] bad-goto: add testcases for linearization of invalid labels Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 03/17] bad-goto: add more testcases Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 04/17] bad-goto: do not linearize if the IR will be invalid Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 05/17] bad-goto: reorg test in evaluate_goto_statement() Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 06/17] bad-goto: simplify testing of undeclared labels Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 07/17] bad-goto: do not linearize function with " Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 08/17] bad-goto: catch labels with reserved names Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 09/17] scope: no memset() needed after __alloc_scope() Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 10/17] scope: move scope opening/ending inside compound_statement() Luc Van Oostenryck
2020-04-13 16:15 ` [PATCH 11/17] scope: make function scope the same as the body block scope Luc Van Oostenryck
2020-04-13 16:16 ` [PATCH 12/17] scope: s/{start,end}_symbol_scope/{start,end}_block_scope/ Luc Van Oostenryck
2020-04-13 16:16 ` [PATCH 13/17] scope: let labels have their own scope Luc Van Oostenryck
2020-04-13 17:30 ` Linus Torvalds
2020-04-13 16:16 ` [PATCH 14/17] scope: add is_in_scope() Luc Van Oostenryck
2020-04-13 16:16 ` [PATCH 15/17] scope: give a scope for labels & gotos Luc Van Oostenryck
2020-04-13 17:52 ` Linus Torvalds
2020-04-13 18:54 ` Luc Van Oostenryck
2020-04-13 19:32 ` Linus Torvalds
2020-04-13 20:00 ` Luc Van Oostenryck
2020-04-13 22:40 ` Linus Torvalds
2020-04-13 23:39 ` Luc Van Oostenryck
2020-04-14 7:49 ` Luc Van Oostenryck
2020-04-14 18:19 ` Linus Torvalds [this message]
2020-04-14 23:09 ` Luc Van Oostenryck
2020-04-15 0:59 ` Linus Torvalds
2020-05-14 22:22 ` Luc Van Oostenryck
2020-04-13 16:16 ` [PATCH 16/17] bad-goto: catch gotos inside expression statements Luc Van Oostenryck
2020-04-13 16:16 ` [PATCH 17/17] bad-goto: cleanup evaluate_goto() 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='CAHk-=wiahqumRaQkkcQ_kFhknA9z==DCWNKK-j0GRJH7GUtPEw@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--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).