extra: more limits on which variables are equivalent
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 28 May 2014 10:45:58 +0000 (28 13:45 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Wed, 28 May 2014 10:45:58 +0000 (28 13:45 +0300)
If the assignment is:

foo = &bar;

Then we don't record that as equivalent.  Unfortunately, I can't remember
why this is.  Probably it is because we don't record the state of &bar in
smatch_extra so they become out of sync.

If the assignment is:

foo = foo->bar;

Then the problem is that after the assignment then the right side of the
assignment has changed so foo != foo->bar at the end.

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

index f14c5be..08dcb5d 100644 (file)
@@ -514,8 +514,11 @@ static void match_vanilla_assign(struct expression *left, struct expression *rig
        right_type = get_type(right);
 
        right_name = expr_to_var_sym(right, &right_sym);
-       if (right_name && right_sym &&
-           types_equiv_or_pointer(left_type, right_type)) {
+
+       if (!(right->type == EXPR_PREOP && right->op == '&') &&
+           right_name && right_sym &&
+           types_equiv_or_pointer(left_type, right_type) &&
+           !has_symbol(right, sym)) {
                set_equiv(left, right);
                goto free;
        }