diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-04-27 02:46:46 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-05-21 17:27:45 +0200 |
commit | c5421b0d1ab0ab2d182ee1c1efbbc20f24275242 (patch) | |
tree | 3b292c82d8430600ab1e45c6e7ff0c6609e0c6ac | |
parent | 25216452d77c39fcb258ff96d44f4f8d55bbda43 (diff) | |
download | sparse-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.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -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) |