[PATCH] Improved plugin/tool support by expanding an existing attribute

Marcwell Helpdesk via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 4 05:26:14 PST 2017

Many plugins/tools could benefit from having a generic way for communicating control directives directly from the source code to itself (via the AST) when acting, for example, as source code transformers, generators, collectors and the like. Attributes are a suitable way of doing this but most available attributes have predefined functionality and modifying the compiler for every plugin/tool is obviously not an option. There is however one undocumented but existing attribute that could be used for a generic solution if it was slightly modified and expanded - the annotate attribute.

The current functionality of the annotate attribute encompass annotating declarations with arbitrary strings using the GNU spelling. The attached patch expands on this functionality by adding annotation of statements, C++11 spelling and documentation. With the patch applied most of the code could be annotated for the use by any Clang plugin or tool. For a more detailed description of the updated attribute, see patch for "AttrDocs.td".

An example demonstratiing the use and syntax of the updated attribute:

  class [[annotate("plain")]] Object
  { . . . };

  int main(int argc, char* argv[]) __attribute((annotate("entry-point")))
    [[annotate("local_var")]]   // Decl annotation
    int n = 1 ;

    // Multiple Stmt annotations
    [[annotate("group-A"), annotate("opt-1:2")]]
    { . . . }
    return 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: attrib-annotate.patch
Type: application/octet-stream
Size: 7480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170204/d2c542a8/attachment.obj>

More information about the cfe-commits mailing list