flow: implied: fix how switch statements are handled
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 26 Nov 2012 08:36:40 +0000 (26 11:36 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Mon, 26 Nov 2012 08:36:40 +0000 (26 11:36 +0300)
We should set the state based on the case statement, regardless.  It
shouldn't be based on the true_sm from get_sm_state_slist().  I have
removed that.

The rest of this change is basically just re-arranging code.

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

index 46f1d4e..be6d44c 100644 (file)
@@ -575,7 +575,6 @@ struct state_list *__implied_case_slist(struct expression *switch_expr,
        char *name = NULL;
        struct symbol *sym;
        struct sm_state *sm;
-       struct sm_state *true_sm;
        struct state_list *true_states = NULL;
        struct state_list *false_states = NULL;
        struct state_list *ret = clone_slist(*raw_slist);
@@ -586,21 +585,22 @@ struct state_list *__implied_case_slist(struct expression *switch_expr,
        if (!name || !sym)
                goto free;
        sm = get_sm_state_slist(*raw_slist, SMATCH_EXTRA, name, sym);
-       if (!case_expr) {
-               vals = top_range_list(*remaining_cases);
-       } else {
-               if (!get_value(case_expr, &sval))
-                       goto free;
 
-               filter_top_range_list(remaining_cases, sval);
-               add_range(&vals, sval, sval);
+       if (case_expr) {
+               if (get_value(case_expr, &sval)) {
+                       filter_top_range_list(remaining_cases, sval);
+                       add_range(&vals, sval, sval);
+               } else {
+                       vals = clone_range_list(top_range_list(*remaining_cases));
+               }
+       } else {
+               vals = top_range_list(*remaining_cases);
        }
+
        if (sm)
                separate_and_filter(sm, SPECIAL_EQUAL, vals, LEFT, *raw_slist, &true_states, &false_states);
 
-       true_sm = get_sm_state_slist(true_states, SMATCH_EXTRA, name, sym);
-       if (!true_sm)
-               set_state_slist(&true_states, SMATCH_EXTRA, name, sym, alloc_estate_range_list(vals));
+       set_state_slist(&true_states, SMATCH_EXTRA, name, sym, alloc_estate_range_list(vals));
        overwrite_slist(true_states, &ret);
        free_slist(&true_states);
        free_slist(&false_states);