[cfe-dev] Clang: checker vs. plugin

Jordan Rose jordan_rose at apple.com
Thu May 1 20:26:47 PDT 2014


Sorry for the delayed response.

On Apr 25, 2014, at 5:44 , Aitor San Juan <aitor.sj at opendeusto.es> wrote:

> Many thanks for the details, Jordan.
> 
> Now new questions arise:
> 
> 1)From your comments, may I conclude that checker-plugins are not in the current development path for Clang/Analyzer? Is that path currently somehow frozen?

There's no intended restriction here, there's just no one working on it. If you run into an issue using checker-plugins, it's likely to go to the bottom of everyone's list. Patches to fix issues with plugins will still be reviewed and accepted, though.


> 
> 2) What additional "actions" could be perfomed on an AST? I can only think of programatically modifying the AST, i.e., programatically changing the source code to make it, for example, compliant with coding rules or the like. Any other uses? I'm still (in the process of) becoming more familiar with this.

We don't actually allow mutation of a built AST, so you don't even get that. But here are some of the actions that happen within Clang's source tree:

- Generate LLVM IR (normal compilation).
- Run the analyzer.
- Run some ASTMatcher-based action (e.g. http://clang.llvm.org/docs/LibASTMatchersTutorial.html)
- Pretty-print the source (I don't think we have this yet).
- Generate a PCH from the parsed AST (-emit-pch).
- Run some refactoring action, like the Objective-C modernizer.
- Do nothing (-fsyntax-only)

There are also actions that consume preprocessor output instead of an AST, but I don't think those can be run from a Plugin in the same way. Not sure, though.

> 
> 3) You say that plugins can also add additional checkers. From the example you mention (MainCallChecker.cpp) and from the documentation in CheckerRegistry.h, what do you exactly mean by "add"? Are you referring to the fact that you register the checker? Am I right if I conclude that if a plugin adds several checkers, these are packed/compiled in the same final DLL for the plugin, and, thus, that's why the plugin needs loading to be able to use its checkers? (in this last case, would it be necessary to rebuild Clang as with a normal checker? I guess it wouldn't).

Right, it wouldn't. CheckerRegistry uses static constructors to do its job, meaning that code is run simply by loading the plugin's DLL. One plugin-DLL can contain any number of checkers, which each get registered with the main executable's CheckerRegistry. At one point I remember hearing that this had issues on Windows, but I don't know what they were and I can't remember any recent complaints. (I work primarily with OS X, but other contributors to the analyzer use Linux, FreeBSD, and Windows.)

Jordan




More information about the cfe-dev mailing list