[cfe-dev] A plugin proposal for clang
annulen at yandex.ru
Sat Oct 15 08:30:13 CDT 2011
15.10.2011, 04:31, "Joshua Cranmer" <Pidgeot18 at gmail.com>:
> This is a document in partial response to Douglas Gregor's recent comment about needing someone to push forward a plugin proposal for clang.
> What kinds of use cases would people have for a compiler plugin?
> * Add a static analyzer
> * Production of ancillary metadata for types and declarations (e.g., adding reflective capabilities to C/C++)
> * Custom optimization passes
> The current architecture appears to assume that clang plugins and clang itself are primarily useful for static analysis and not for production. If I wish to use a plugin, I have to use:
> clang -cc1 -load /path/to/plugin.so -plugin Foo -plugin-arg-Foo Bar
> But if I'm trying to drop in this plugin in a regular build, I need to do:
> clang -Xclang -load -Xclang /path/to/plugin.so -Xclang -add-plugin -Xclang Foo -Xclang -plugin-arg-Foo -Xclang Bar
> By comparison, a gcc plugin lets me do:
> gcc -fplugin=/path/to/plugin.so -fplugin-arg-plugin-bar=baz
I've proposed it a while ago:
> The key things that gcc lets me do in a plugin that I think are necessary for clang are to be able to define custom attributes and pragmas, which are largely necessary for custom static analysis scripts: for example, Mozilla defines several attributes to allow checking of properties in their gcc plugins (e.g., enforcing outparameter guidelines). All of its other features appear to be either an artifact of its code design (e.g., GC interactions) or features that are already supported (e.g., adding a new optimization pass).
More information about the cfe-dev