Libclang static analyzer


Is it possible to run the static analyzer and get the diagnostics with libclang?

I'm thinking some command line option could enable it and then you get
the diagnostics, ranges and fixits as usual, but nothing I've tried
seems to do the trick. Am I missing something or is it just not
supported? What would it take to get it to work?

The use case I'm trying to enable is static analyzer support via a
python plugin for a text editor.

Many thanks,


Great, I didn't know that.

Is there anyway to get libclang to spit out a plist or get the
diagnostics via the libclang api though? On the *nixes it's not a big
problem, but on Windows libclang.dll is much easier to ship with the
plugin compared to requiring users to install the full clang



The Static Analyzer (as well as CodeGen) is not a part of libclang. Most likely it should stay that way since libclang is mostly responsible for AST queries (syntax only analyzes).


Hi Fredrik,

The current answer is no. We could possibly enhance the analyzer to emit a new serialized format (e.g., bitcode) that can then be read back in via a separate libclang interface. This is something I'd like to do at some point. This allows libclang not to link in the analyzer, but does allow it to consume its output. We recently enhanced libclang to read in serialized compiler diagnostics, so providing a new set of API hooks for reading in analyzer diagnostics would not be bad. What would be really neat is if we had such a C API in place, this enables the construction of a bunch of rich clients (e.g., via the Python bindings) for analyzer diagnostics.