From b307a6b54da61e462c726619dc45b2f19e850c6d Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Tue, 5 May 2020 17:55:41 +0200 Subject: bad-label: check for unused labels Issue a warning if a label is defined but not used. Note: this should take in account the attribute 'unused'. Signed-off-by: Luc Van Oostenryck --- scope.c | 8 ++++++++ validation/label-unused.c | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scope.c b/scope.c index 635e0d6d..3a0d784f 100644 --- a/scope.c +++ b/scope.c @@ -150,6 +150,14 @@ void start_label_scope(void) void end_label_scope(void) { + struct symbol *sym; + + FOR_EACH_PTR(label_scope->symbols, sym) { + if (!sym->stmt || sym->used) + continue; + warning(sym->pos, "unused label '%s'", show_ident(sym->ident)); + } END_FOR_EACH_PTR(sym); + end_scope(&label_scope); } diff --git a/validation/label-unused.c b/validation/label-unused.c index c136c7a8..a654ef77 100644 --- a/validation/label-unused.c +++ b/validation/label-unused.c @@ -15,7 +15,6 @@ l: /* * check-name: label-unused - * check-known-to-fail * * check-error-start label-unused.c:3:1: warning: unused label 'l' -- cgit 1.2.3-korg