llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.08k stars 11.99k forks source link

[Umbrella][Checkers] Dead code detection. #3035

Open llvmbot opened 16 years ago

llvmbot commented 16 years ago
Bugzilla Link 2663
Version unspecified
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @haoNoQ

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.

haoNoQ commented 5 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.

llvmbot commented 13 years ago

Unreachable code analysis is already very useful to detect trivial errors, like code after a return etc.

llvmbot commented 16 years ago

assigned to @tkremenek