[cfe-dev] Idea for better invoking static analysis via command line

Anna Zaks via cfe-dev cfe-dev at lists.llvm.org
Fri Feb 5 11:49:42 PST 2016


> On Feb 5, 2016, at 4:26 AM, David Chisnall via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> On 4 Feb 2016, at 23:52, via cfe-dev <Alexander G. Riccio> wrote:
>> 
>> Adding a flag to a build is also a much lower barrier to entry to get
>> started.  
>> 
>> Example #1: I don't have Perl. Not many machines have Perl. That makes scan-build problematic.
>> 
>> "Not many" is relative to Python. Python ate the world.
>> 
> 
> Neither Python nor Perl is in the FreeBSD base system.  Additionally, we can very easily add flags to our build system, but we can’t reliably run it to completion with something that interposes on CC, because various things define a different CC for different things.
> 

The new scan-build rewrite can interpose on the build system without interposing on CC. It produces a compilation database as output.
http://llvm.org/viewvc/llvm-project?view=revision&revision=257533
http://reviews.llvm.org/D9600

As I’ve explained in the the other thread (http://clang-developers.42468.n3.nabble.com/Proposal-Integrate-static-analysis-test-suites-td4048967.html <http://clang-developers.42468.n3.nabble.com/Proposal-Integrate-static-analysis-test-suites-td4048967.html>), there are reasons to discourage usage of the static analyzer directly from command line:

"Most importantly, end users should never invoke the analyzer by calling “clang —analyze” since “clang —analyze” is an implementation detail of the static analyzer. The only advertised user facing clang static analysis tool is scan-build (see http://clang-analyzer.llvm.org <http://clang-analyzer.llvm.org/>). Here are some reasons for that. For one, it is almost impossible to understand why the static analyzer warns without examining the error paths. Second, the analyzer could be extended to perform whole project analysis in the future and "clang —analyze" works with a single TU at a time.

I agree that the best user experience is to report all warnings in one place, while still differentiating which warning was reported by which tool. It would be awesome if the results from all bug finding tools such as the clang static analyzer, the compiler, and clang-tidy would be reported through the same interface.

The CodeChecker team is working on a solution for that and I hope we can incorporate their technology in LLVM/clang.
"

> Having a well-documented set of flags for static analysis would also make it much easier to integrate with systems such as CMake.  I’d love to be able to kick off a build in our CI systems for things that use CMake that would do the build and analysis in parallel, with neither blocking the other, and be able to start running tests once the build has finished, even if the static analysis is still ongoing.  All of the dependency metadata for doing this exists in our build system, none of it is easily exploited by scan-build (for things that use CMake, all of it could be extracted from the generated JSON, but it would be nicer to just have some separate targets that ninja knew were independent top-level things).

As others mentioned in that thread, even though we do not encourage using 'clang —analyze’, the options are documented in clang help, so you could integrate it into your build system. The main issues would be hard to understand results and possibility that the integration is going to break in the future.

> 
> David
> 
> _______________________________________________
> 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/20160205/4b504eef/attachment.html>


More information about the cfe-dev mailing list