From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v1 13/28] scope: move scope opening/ending inside compound_statement()
Date: Tue, 19 May 2020 02:57:13 +0200 [thread overview]
Message-ID: <20200519005728.84594-14-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200519005728.84594-1-luc.vanoostenryck@gmail.com>
A compound statement starts and ends a block scope, so
it's better to start & end this scope inside the function
parsing the statement: compound_statement.
The only exception is for the body of a function where
the scope also enclose the parameter declaration but that
is fine since the function is special anyway.
Move the calls to start & close the block scope inside
compound_statement() and directly call statement_list()
for the function body.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
expression.c | 2 --
parse.c | 13 ++++++-------
2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/expression.c b/expression.c
index 5b9bddfe456e..78e577cf10a1 100644
--- a/expression.c
+++ b/expression.c
@@ -71,9 +71,7 @@ struct token *parens_expression(struct token *token, struct expression **expr, c
struct statement *stmt = alloc_statement(token->pos, STMT_COMPOUND);
*expr = e;
e->statement = stmt;
- start_symbol_scope();
token = compound_statement(token->next, stmt);
- end_symbol_scope();
token = expect(token, '}', "at end of statement expression");
} else
token = parse_expression(token, expr);
diff --git a/parse.c b/parse.c
index 9e7b74f98638..e23c5b64e8be 100644
--- a/parse.c
+++ b/parse.c
@@ -2555,11 +2555,7 @@ static struct token *statement(struct token *token, struct statement **tree)
}
if (match_op(token, '{')) {
- stmt->type = STMT_COMPOUND;
- start_symbol_scope();
token = compound_statement(token->next, stmt);
- end_symbol_scope();
-
return expect(token, '}', "at end of compound statement");
}
@@ -2666,7 +2662,10 @@ static struct token *parameter_type_list(struct token *token, struct symbol *fn)
struct token *compound_statement(struct token *token, struct statement *stmt)
{
+ stmt->type = STMT_COMPOUND;
+ start_symbol_scope();
token = statement_list(token, &stmt->stmts);
+ end_symbol_scope();
return token;
}
@@ -2818,15 +2817,15 @@ static struct token *parse_function_body(struct token *token, struct symbol *dec
decl->ctype.modifiers |= MOD_EXTERN;
stmt = start_function(decl);
-
*p = stmt;
+
FOR_EACH_PTR (base_type->arguments, arg) {
declare_argument(arg, base_type);
} END_FOR_EACH_PTR(arg);
- token = compound_statement(token->next, stmt);
WARNING: multiple messages have this Message-ID (diff)
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v1 13/28] scope: move scope opening/ending inside compound_statement()
Date: Tue, 19 May 2020 02:57:13 +0200 [thread overview]
Message-ID: <20200519005728.84594-14-luc.vanoostenryck@gmail.com> (raw)
Message-ID: <20200519005713.AW3HlK7jTkr1lxO2m9jcAfss8_5W5oGJaV01QzJuaeA@z> (raw)
In-Reply-To: <20200519005728.84594-1-luc.vanoostenryck@gmail.com>
A compound statement starts and ends a block scope, so
it's better to start & end this scope inside the function
parsing the statement: compound_statement.
The only exception is for the body of a function where
the scope also enclose the parameter declaration but that
is fine since the function is special anyway.
Move the calls to start & close the block scope inside
compound_statement() and directly call statement_list()
for the function body.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
expression.c | 2 --
parse.c | 13 ++++++-------
2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/expression.c b/expression.c
index 5b9bddfe456e..78e577cf10a1 100644
--- a/expression.c
+++ b/expression.c
@@ -71,9 +71,7 @@ struct token *parens_expression(struct token *token, struct expression **expr, c
struct statement *stmt = alloc_statement(token->pos, STMT_COMPOUND);
*expr = e;
e->statement = stmt;
- start_symbol_scope();
token = compound_statement(token->next, stmt);
- end_symbol_scope();
token = expect(token, '}', "at end of statement expression");
} else
token = parse_expression(token, expr);
diff --git a/parse.c b/parse.c
index 9e7b74f98638..e23c5b64e8be 100644
--- a/parse.c
+++ b/parse.c
@@ -2555,11 +2555,7 @@ static struct token *statement(struct token *token, struct statement **tree)
}
if (match_op(token, '{')) {
- stmt->type = STMT_COMPOUND;
- start_symbol_scope();
token = compound_statement(token->next, stmt);
- end_symbol_scope();
-
return expect(token, '}', "at end of compound statement");
}
@@ -2666,7 +2662,10 @@ static struct token *parameter_type_list(struct token *token, struct symbol *fn)
struct token *compound_statement(struct token *token, struct statement *stmt)
{
+ stmt->type = STMT_COMPOUND;
+ start_symbol_scope();
token = statement_list(token, &stmt->stmts);
+ end_symbol_scope();
return token;
}
@@ -2818,15 +2817,15 @@ static struct token *parse_function_body(struct token *token, struct symbol *dec
decl->ctype.modifiers |= MOD_EXTERN;
stmt = start_function(decl);
-
*p = stmt;
+
FOR_EACH_PTR (base_type->arguments, arg) {
declare_argument(arg, base_type);
} END_FOR_EACH_PTR(arg);
- token = compound_statement(token->next, stmt);
-
+ token = statement_list(token->next, &stmt->stmts);
end_function(decl);
+
if (!(decl->ctype.modifiers & MOD_INLINE))
add_symbol(list, decl);
check_declaration(decl);
--
2.26.2
next prev parent reply other threads:[~2020-05-19 0:57 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 0:57 [SPARSE v2 00/28] detect invalid branches Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 01/28] misc: fix testcase typeof-safe Luc Van Oostenryck
2020-05-20 0:33 ` Ramsay Jones
2020-05-20 15:34 ` Ramsay Jones
2020-05-20 16:12 ` Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 02/28] misc: s/fntype/rettype/ Luc Van Oostenryck
2020-05-20 0:35 ` Ramsay Jones
2020-05-20 16:39 ` Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 03/28] misc: always use the node for current_fn Luc Van Oostenryck
2020-05-20 0:37 ` Ramsay Jones
2020-05-19 0:57 ` [PATCH v1 04/28] bad-goto: add testcase for 'jump inside discarded expression statement' Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 05/28] bad-goto: add testcases for linearization of invalid labels Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 06/28] bad-goto: reorganize testcases and add some more Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 07/28] bad-goto: do not linearize if the IR will be invalid Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 08/28] bad-goto: reorg test in evaluate_goto_statement() Luc Van Oostenryck
2020-05-19 0:57 ` Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 09/28] bad-goto: simplify testing of undeclared labels Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 10/28] bad-goto: do not linearize function with " Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 11/28] bad-goto: catch labels with reserved names Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 12/28] scope: no memset() needed after __alloc_scope() Luc Van Oostenryck
2020-05-19 0:57 ` Luc Van Oostenryck [this message]
2020-05-19 0:57 ` [PATCH v1 13/28] scope: move scope opening/ending inside compound_statement() Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 14/28] scope: extract bind_symbol_with_scope() from bind_symbol() Luc Van Oostenryck
2020-05-20 0:44 ` Ramsay Jones
2020-05-19 0:57 ` [PATCH v1 15/28] scope: __func__ is special Luc Van Oostenryck
2020-05-20 0:45 ` Ramsay Jones
2020-05-19 0:57 ` [PATCH v1 16/28] scope: __label__ " Luc Van Oostenryck
2020-05-20 0:47 ` Ramsay Jones
2020-05-19 0:57 ` [PATCH v1 17/28] scope: s/{start,end}_symbol_scope/{start,end}_block_scope/ Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 18/28] scope: make function_scope invalid outside functions Luc Van Oostenryck
2020-05-19 1:38 ` Linus Torvalds
2020-05-19 20:57 ` Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 19/28] scope: let labels have their own scope Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 20/28] scope: add is_in_scope() Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 21/28] scope: give a scope for labels & gotos Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 22/28] bad-goto: jumping inside a statemet expression is an error Luc Van Oostenryck
2020-05-20 0:53 ` Ramsay Jones
2020-05-20 16:37 ` Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 23/28] bad-goto: label expression inside a statement expression is UB Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 24/28] bad-goto: extract check_label_declaration() Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 25/28] bad-goto: check declaration of label expressions Luc Van Oostenryck
2020-05-20 0:56 ` Ramsay Jones
2020-05-19 0:57 ` [PATCH v1 26/28] bad-label: check for unused labels Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 27/28] bad-label: mark labels as used when needed Luc Van Oostenryck
2020-05-19 0:57 ` [PATCH v1 28/28] bad-label: respect attribute((unused)) Luc Van Oostenryck
2020-05-19 1:41 ` [SPARSE v2 00/28] detect invalid branches Linus Torvalds
2020-05-19 21:16 ` 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=20200519005728.84594-14-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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