organizing a clang static analyzer checker project

Dear Clang Developers,

I am wondering about the best way to organize a project with several custom Clang Static Analyzer checkers.

Currently, we are compiling the custom checkers as plugins and load them dynamically with -load on the command line. This has the benefit of having a fast compile time, but it does not work (well) on Windows and it’s not nice for the end user.

The standard way, to add them in llvm/tools/clang/lib/StaticAnalyzer as described in https://clang-analyzer.llvm.org/checker_dev_manual.html, has the downsides of (1) having a large compilation time and (2) being in a place which is not directly under our source code control system.

I am wondering if there is a third way to organize things. Ideally, we would like to have

  • fast compilation times;
  • our checkers in a directory outside of the clang tree;
  • easy on the end users (a static build of clang);
  • our checkers working nicely on Windows.

The llvm tree has a “projects” directory under which they recommend to place external projects, but there are no guidelines on how to add CSA checkers there.

I would appreciate if you could provide some pointers on how to best organize our project.

Thank you!

Best,
Stefan

Dear Stefan,

I've posted a demo here:
https://github.com/nsumner/clang-plugins-demo

This shows how you can make a standalone executable that automatically
loads your own static analyzer plugins from your external project.
I've not tried it out on Windows (and expect it to require tweaks),
but it can point you along the way.

Best,
Nick

I think Nick's -fplugin approach is equivalent to Stefan's -load approach, please correct me if i'm wrong :slight_smile:

Stefan: i don't have much to present. I guess your main complication is Checkers.td which is a single registry of all checkers within the clang's executable. If only you could extend it to become more "modular", that'd probably help.

Probably you'd be happy with simply extending Checkers.td to look for checkers in directories other than lib/StaticAnalyzer/Checkers: eg. hardcode lib/StaticAnalyzer/ExternalCheckers, or even lib/StaticAnalyzer/Checkers/External, as an alternate path which would be your code repo.