extra: handle canonical for loops with unknown ends better
commitd25d5f206eb6c6ee55941c36939bb5dc6d9e1628
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 7 Jan 2021 14:23:56 +0000 (7 17:23 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Thu, 7 Jan 2021 14:23:56 +0000 (7 17:23 +0300)
tree9d7a72dafe0577f43b981bc5b53fb734d65527ca
parentde60d9ea7bcf7bc658a808adc2133aaa6ddc48d1
extra: handle canonical for loops with unknown ends better

Smatch has always handled loops in sort of a hacky way which is sort of
the way that humans read loops instead of the way that computers probably
aught to read them.  The reason for this is because my instinct says that
handling loops properly is going to be slow.

Anyway, the way that it handles them is it tries to find out what the
limit is and then what the possible values of for "i" inside and at the
exit condition.

for (i = 0; i < XXX; i++) {

And this works fine when XXX is a literal but it doesn't work when XXX
isn't known.  In the current code, XXX is unknown then what smatch used to
do was just say that i is zero inside the loop and unknown outside the
loop.

So what this patch does is it says i is "0-s32max" inside the loop and it
exits the loop with "i == s32max".  Which is hopefully equivalent to just
saying "i is unknown".

We could try to be more precise than that if we knew that the limit was
"8-20" or something but they truth is I didn't really try that.  It might
be a good idea.

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