aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-04-27 02:46:46 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-05-21 17:27:45 +0200
commitc5421b0d1ab0ab2d182ee1c1efbbc20f24275242 (patch)
tree3b292c82d8430600ab1e45c6e7ff0c6609e0c6ac
parent25216452d77c39fcb258ff96d44f4f8d55bbda43 (diff)
downloadsparse-c5421b0d1ab0ab2d182ee1c1efbbc20f24275242.tar.gz
bad-goto: extract check_label_declaration()
Extract this helper from evaluate_goto_statement(). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--evaluate.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/evaluate.c b/evaluate.c
index 21d5d761..b272e3f6 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3257,6 +3257,21 @@ static struct symbol *evaluate_offsetof(struct expression *expr)
return size_t_ctype;
}
+static void check_label_declaration(struct position pos, struct symbol *label)
+{
+ switch (label->namespace) {
+ case NS_LABEL:
+ if (label->stmt)
+ break;
+ sparse_error(pos, "label '%s' was not declared", show_ident(label->ident));
+ /* fallthrough */
+ case NS_NONE:
+ current_fn->bogus_linear = 1;
+ default:
+ break;
+ }
+}
+
struct symbol *evaluate_expression(struct expression *expr)
{
if (!expr)
@@ -3748,12 +3763,7 @@ static void evaluate_goto_statement(struct statement *stmt)
return;
}
- if (label->namespace == NS_LABEL && !label->stmt) {
- sparse_error(stmt->pos, "label '%s' was not declared", show_ident(label->ident));
- current_fn->bogus_linear = 1;
- }
- if (label->namespace == NS_NONE)
- current_fn->bogus_linear = 1;
+ check_label_declaration(stmt->pos, label);
}
struct symbol *evaluate_statement(struct statement *stmt)