comparison: handle merging comparisons
This is a pretty involved patch. Theoretically I could have broken it up
into two parts, but when I'm coding my own stuff then I have no standards
so it's all going in as one big patch.
The code we care about looks like this:
if (x < 10)
y = x;
else
y = 10;
__smatch_compare(x, y);
On the first branch y == x. On the second branch we wouldn't normally
store the relationship between x and y so we have an unmatched state. We
can determine the relationship though. Then we merge the states together
to get the final relationship.
The first thing to say is that smatch_compare.c didn't used to store the
name and symbols of the variables being compared. So I had to create a
dynamically allocated smatch_state so that information could be stored in
the ->data.
The next part of the change is if there is an unmatched state. We can get
the implied range list for both variables and determine the relationship
from that. y is 10. x is 10-max. That means y <= x.
Then when we merge it it's simple enough y == x and y <= x combine to say
that y <= x.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>