Open llvmbot opened 16 years ago
Various checkers for dead code are indeed useful, but the techniques they require are completely different from what most Static Analyzer checkers do, because they are usually "must" problems (i.e., something needs to happen (or not happen) across all paths through a certain set of lines of code), but most Static Analyzer checkers solve "may" problems (i.e., there exists a path on which an invariant is violated).
Static Analyzer's symbolic execution engine is not fit for must-problems because it does not guarantee to explore all paths through the program. But we could address that with a more generic data flow engine.
Another approach to that would be to make the symbolic execution engine take notes of every moment when it drops paths, so that to emit dead code warnings whenever no paths were dropped but a certain area of code was still not covered.
Currently we have a "dead stores" checker that finds variables that were initialized in a non-trivial manner but never used (before going out of scope or being overwritten). This is a typical must-problem that is solved via a separate data flow analysis pass independent of the rest of the Static Analyzer. This checker turned out to be very complicated and we will probably not jump into doing more of them before coming up with a more generic approach.
Unreachable code analysis is already very useful to detect trivial errors, like code after a return etc.
assigned to @tkremenek
Extended Description
It would be very nice to be able to get warnings that particular methods or classes are probably not being used. Of course with Objective C being dynamic and all, it is possible to have a number of false positives, but it would be very handy to have. If you were able to notice performSelector: invocations and not mark methods as being called, or know about delegate methods, that would be cool.