From 2e49465d770ce21d87b2a0a689579c4335984419 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 11 Feb 2010 14:10:45 +0300 Subject: [PATCH] print an error message about unreached initializers For example: switch (x) { int y = 42; case 1: .... In this example, y doesn't actually get set to 42. Signed-off-by: Dan Carpenter --- smatch_flow.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/smatch_flow.c b/smatch_flow.c index 07421c4b..3a815347 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -291,6 +291,17 @@ static void handle_post_loop(struct statement *stmt) } } +static void print_unreached_initializers(struct symbol_list *sym_list) +{ + struct symbol *sym; + + FOR_EACH_PTR(sym_list, sym) { + if(sym->initializer) + sm_msg("error: '%s' is not actually initialized (unreached code).", + (sym->ident ? sym->ident->name : "this variable")); + } END_FOR_EACH_PTR(sym); +} + static void print_unreached(struct statement *stmt) { @@ -304,7 +315,9 @@ static void print_unreached(struct statement *stmt) case STMT_COMPOUND: /* after a switch before a case stmt */ case STMT_CASE: case STMT_LABEL: + break; case STMT_DECLARATION: /* switch (x) { int a; case foo: ... */ + print_unreached_initializers(stmt->declaration); break; default: if (print) -- 2.11.4.GIT