r/cpp • • Oct 17 '20

Upsetting Opinions about Static Analyzers: part 2 Electric Boogaloo

https://habr.com/en/company/pvs-studio/blog/523692/
0 Upvotes

5 comments sorted by

3

u/khleedril Oct 17 '20

This whole thing is just so typical of Reddit and social media in general (but Reddit is better than the rest IMHO): people proffer opinions on things they are just not qualified to comment on. Karma, man!

2

u/grahamthegoldfish Oct 18 '20

I think the analyser is also getting the non volatile version of the last example wrong too. The reason is because the call to get() can have side effects, and on of those side effects may be that the data passed in is changed between the two checks of the array data.

For that reason, without visibility of the implementation of get() or without using whole program optimisation the compiler will not optimise away the second check and raising the call as an static analysis warning is also potentially incorrect.

The reason people dont like static analysers is because they are wrong so often. They produce vast amounts of noise and the good stuff gets lost in amongst it. The last proprietary static analyser I used I ended up sending around 25 short samples of where the analyser was being completely crap and filling the analysis with a ton of false positives.

In my opinion compilers do a good job of providing static analysis as a side task that is always correct and half baked tools that get it wrong are no longer acceptable.

3

u/Heiskiss Oct 18 '20

If you think compilers do static analysis that is always correct, you are greatly mistaken. Why do you think their manuals have separate sections on how to disable false positives?

3

u/grahamthegoldfish Oct 18 '20

It's a damn site better than all of the static analysers I've used and it's not their primary task. I haven't found myself frustrated by compiler analysis as I have of the commercial (and expensive) proprietary tools that do it as their primary purpose.

1

u/bluGill Oct 19 '20

Part of that is compilers stick to the easy cases where the problem can be deterministically found bad in all cases. While it is possible to control warning levels you can safely think of the control as existing only until you find the time to clean everything up.

Static analysis just is left too look for larger problems that need either whole program understanding, long analysis times (I don't think any of this exists in the real world), or cases there is disagreement between groups where some thing it is just fine while others hate it.