[cfe-dev] RFC clang analyzer false positives (for loop)

Sean Eveson via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 25 08:15:16 PDT 2016


Hi,

I've seen the analyzer find real problems where loops are not executed and
think this is very useful. Personally I'd rather see the warnings and add
asserts, which makes it clearer that 'nr' must be greater than 1, making it
less likely someone will add an incorrect call in the future. While that is
a preference for avoiding false negatives over false positives, I think it
is reasonable in this case given there is no analysis across translation
units.

You tend to get false positives when the Analyzer can't see any calls to
the function, so doesn't know 'nr' can never be less than 1. You can get
false negatives when the analyzer can only see some of the calls.

Sean Eveson
SN Systems - Sony Computer Entertainment Group

On Thu, Aug 25, 2016 at 8:55 AM, Daniel Marjamäki via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello!
>
> One more email about false positives.
>
> I see many false positives in code like this:
>
>     int f(int nr) {
>       int x;
>       for (int i = 0; i < nr; ++i) {
>         x = i;
>       }
>       return x;
>     }
>
> Theoretically, if "nr" is less than 0 then the return value will be
> uninitialized.
>
> As far as I have seen we know that such loops are executed at least once
> very often. I can't remember a TP where it was possible that such loop code
> would not be executed.
>
> Can we try to fix this so the analyzer will be silent for the above code?
> I would like that if the variable is unconditionally written in the loop
> code there should be no warning.
>
> Best regards,
> Daniel Marjamäki
>
> ............................................................
> ......................................................
> Daniel Marjamäki Senior Engineer
> Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden
>
> Mobile:                 +46 (0)709 12 42 62
> E-mail:                 Daniel.Marjamaki at evidente.se
>
> www.evidente.se
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160825/9226b845/attachment.html>


More information about the cfe-dev mailing list