unreachable code: don't warn about unreachable break statements
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 19 Dec 2013 15:23:39 +0000 (19 18:23 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Thu, 19 Dec 2013 15:23:39 +0000 (19 18:23 +0300)
A lot of people do stuff like:

switch (foo) {
case X:
....
return ret;
break;
case Y:

I think it sucks when people do this.  Smatch used to warn about it when
--spammy was enabled, but actually I never sent patches for these.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch_flow.c

index 3532bfc..b1aff67 100644 (file)
@@ -516,7 +516,9 @@ static void print_unreached(struct statement *stmt)
                        return;
                break;
        case STMT_GOTO:
-               if (!option_spammy)
+               /* people put extra breaks inside switch statements */
+               if (stmt->goto_label && stmt->goto_label->type == SYM_NODE &&
+                   strcmp(stmt->goto_label->ident->name, "break") == 0)
                        return;
                break;
        default: