comparison: partially fix how links are updated
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 29 Jun 2013 09:12:51 +0000 (29 12:12 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Sat, 29 Jun 2013 09:12:51 +0000 (29 12:12 +0300)
The problem is that a link is a var/sym pair but when you have three
variables then one chunks is not a var/sym pair.  It works fine if you
are creating a new state, in that case you just create three links.  But
where it falls down is when you are inheriting comparisons and don't have
access to the original expression pointer or the var/sym pairs.

Anyway, this fixes it slightly for creating new links.

There is no point in creating a link for a chunk without a sym pointer so
I have removed that.

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

index 44c7d7f..2167dc2 100644 (file)
@@ -589,15 +589,8 @@ static void save_link(struct expression *expr, char *link)
 
        expr = strip_expr(expr);
        if (expr->type == EXPR_BINOP) {
-               char *chunk;
-
-               chunk = chunk_to_var(expr);
-               if (!chunk)
-                       return;
-
                save_link(expr->left, link);
                save_link(expr->right, link);
-               save_link_var_sym(chunk, NULL, link);
                return;
        }
 
@@ -765,6 +758,8 @@ static void add_comparison(struct expression *left, int comparison, struct expre
        char *left_name = NULL;
        char *right_name = NULL;
        struct symbol *left_sym, *right_sym;
+       struct smatch_state *state;
+       char state_name[256];
 
        left_name = chunk_to_var_sym(left, &left_sym);
        if (!left_name)
@@ -773,7 +768,22 @@ static void add_comparison(struct expression *left, int comparison, struct expre
        if (!right_name)
                goto free;
 
-       add_comparison_var_sym(left_name, left_sym, comparison, right_name, right_sym);
+       if (strcmp(left_name, right_name) > 0) {
+               struct symbol *tmp_sym = left_sym;
+               char *tmp_name = left_name;
+
+               left_name = right_name;
+               left_sym = right_sym;
+               right_name = tmp_name;
+               right_sym = tmp_sym;
+               comparison = flip_op(comparison);
+       }
+       snprintf(state_name, sizeof(state_name), "%s vs %s", left_name, right_name);
+       state = alloc_compare_state(left_name, left_sym, comparison, right_name, right_sym);
+
+       set_state(compare_id, state_name, NULL, state);
+       save_link(left, state_name);
+       save_link(right, state_name);
 
 free:
        free_string(left_name);