[cfe-dev] Handling of loops in the Clang Static Analyzer
Devin Coughlin via cfe-dev
cfe-dev at lists.llvm.org
Fri Feb 24 11:54:33 PST 2017
Hi Venugopal,
> On Feb 23, 2017, at 7:07 PM, Venugopal Raghavan via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> I am re-sending the question I asked under a different thread so that the subject is more relevant to the topic.
>
> I did not quite realize it earlier but it seems that the static analyzer unrolls a loop up to a certain number of times and then stops exploring paths beyond that. In the checker I have written, I get the message "Block count exceeded" and then state exploration stops. As a result, my checker give false positives and does not achieve what it sets out to do.
The analyzer makes no promises about exhaustivity and in many cases will drop flows and stop path exploration. If your analysis depends on full path exploration to prevent false positives (as compared to false negatives) then it is going to be an uphill battle to eliminate false positives.
As you noted, for concrete-bound loops stopping path exploration can be particularly pernicious because after unrolling the loop N times the analyze simply stops. Any code dominated by the loop exit will simply not be explored, leading to false negatives.
Sean Eveson (cc’d) did some initial work on loop widening to mitigate this problem. The basic idea there was rather than simply stopping, the analyzer would “forget” any specific information about a particular iteration through the loop and proceed analyzing after the loop without any assumptions about how many times the loop was unrolled. This would lose some precision but gain coverage for code after the loop. This feature not complete and is off by default, but you can see the beginnings of it at <https://reviews.llvm.org/D12358>
Devin
More information about the cfe-dev
mailing list