<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 9 feb 2017, at 15:07, Aaron Ballman <<a href="mailto:aaron@aaronballman.com" class="">aaron@aaronballman.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Sat, Feb 4, 2017 at 8:26 AM, Marcwell Helpdesk via cfe-commits</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><</span><a href="mailto:cfe-commits@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">cfe-commits@lists.llvm.org</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">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.<br class=""><br class="">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".<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I definitely agree with the premise for this work -- having a generic</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">way for Clang to pass attributed information down to LLVM IR is</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">desirable. However, I'm not convinced that the annotate attribute is</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">the correct approach over something like pluggable attributes. My</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">primary concerns stem from the fact that the annotate attribute has no</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">safe guards for feature collisions (you have to pick a unique string,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">or else you collide with someone else's string, but there's nothing</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">that forces you to do this), has no mechanisms for accepting arguments</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">in a consistent fashion, and provides no way to check the semantics of</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">the attribute. It's basically a minimum viable option for lowering</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">attributed information down to LLVM IR, which is fine for things that</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">aren't in the user's face, but isn't a good general-purpose solution.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I do not have a problem with adding a C++11 spelling to the annotate</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">attribute for the cases we already support, and I definitely think we</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">should document the attribute. But I don't think it makes sense to add</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">it as a statement attribute (and the current patch also leaves out</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">type attributes).</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Some quick thoughts on the patch:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Index: include/clang/Basic/Attr.td<br class="">===================================================================<br class="">--- include/clang/Basic/Attr.td (revision 293612)<br class="">+++ include/clang/Basic/Attr.td (working copy)<br class="">@@ -462,9 +462,10 @@<br class="">}<br class=""><br class="">def Annotate : InheritableParamAttr {<br class="">- let Spellings = [GNU<"annotate">];<br class="">+ let Spellings = [GNU<"annotate">,<br class="">+ CXX11<"", "annotate", 201612>];<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">This should be in the clang namespace and should not be given a third</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">argument (it's not a standards-based attribute).</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""> let Args = [StringArgument<"Annotation">];<br class="">- let Documentation = [Undocumented];<br class="">+ let Documentation = [AnnotateDocs];<br class="">}<br class=""><br class="">def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {<br class="">Index: lib/Sema/SemaStmtAttr.cpp<br class="">===================================================================<br class="">--- lib/Sema/SemaStmtAttr.cpp (revision 293612)<br class="">+++ lib/Sema/SemaStmtAttr.cpp (working copy)<br class="">@@ -23,6 +23,24 @@<br class="">using namespace clang;<br class="">using namespace sema;<br class=""><br class="">+static Attr *handleAnnotateAttr(Sema &S, Stmt *St, const AttributeList &A,<br class="">+ SourceRange Range) {<br class="">+ // Assert string literal as the annotation's argument.<br class="">+ StringRef Str;<br class="">+ if (!S.checkStringLiteralArgumentAttr(A, 0, Str))<br class="">+ return nullptr;<br class="">+<br class="">+ // Assert single argument<br class="">+ if (A.getNumArgs() > 1) {<br class="">+ S.Diag(A.getLoc(), diag::err_attribute_wrong_number_arguments)<br class="">+ << A.getName() << 1;<br class="">+ return nullptr;<br class="">+ }<br class="">+<br class="">+ return ::new (S.Context) AnnotateAttr(A.getRange(), S.Context, Str,<br class="">+ A.getAttributeSpellingListIndex());<br class="">+}<br class="">+<br class="">static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const AttributeList &A,<br class=""> SourceRange Range) {<br class=""> FallThroughAttr Attr(A.getRange(), S.Context,<br class="">@@ -273,6 +291,8 @@<br class=""> diag::warn_unhandled_ms_attribute_ignored :<br class=""> diag::warn_unknown_attribute_ignored) << A.getName();<br class=""> return nullptr;<br class="">+ case AttributeList::AT_Annotate:<br class="">+ return handleAnnotateAttr(S, St, A, Range);<br class=""> case AttributeList::AT_FallThrough:<br class=""> return handleFallThroughAttr(S, St, A, Range);<br class=""> case AttributeList::AT_LoopHint:<br class="">Index: test/SemaCXX/attr-annotate.cpp<br class="">===================================================================<br class="">--- test/SemaCXX/attr-annotate.cpp (nonexistent)<br class="">+++ test/SemaCXX/attr-annotate.cpp (working copy)<br class="">@@ -0,0 +1,17 @@<br class="">+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s<br class="">+<br class="">+[[annotate("foo")]] void foo() {<br class="">+ // C++11 decl annotations<br class="">+ [[annotate("bar")]] int x;<br class="">+ [[annotate(1)]] int y; // expected-error {{'annotate' attribute requires a string}}<br class="">+ [[annotate("bar", 1)]] int z1; // expected-error {{'annotate' attribute takes one argument}}<br class="">+ [[annotate()]] int z2; // expected-error {{'annotate' attribute takes one argument}}<br class="">+ [[annotate]] int z3; // expected-error {{'annotate' attribute takes one argument}}<br class="">+<br class="">+ // C++11 NullStmt annotations<br class="">+ [[annotate("bar")]];<br class="">+ [[annotate(1)]]; // expected-error {{'annotate' attribute requires a string}}<br class="">+ [[annotate("bar", 1)]]; // expected-error {{'annotate' attribute takes one argument}}<br class="">+ [[annotate()]]; // expected-error {{'annotate' attribute takes one argument}}<br class="">+ [[annotate]]; // expected-error {{'annotate' attribute takes one argument}}<br class="">+}<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">There should be some codegen tests that show the attribute is properly</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">finding its way down to the LLVM IR. For instance, what would an</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">annotate attribute on a null statement get lowered to? How about a</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">switch statement?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Index: include/clang/Basic/AttrDocs.td<br class="">===================================================================<br class="">--- include/clang/Basic/AttrDocs.td (revision 293612)<br class="">+++ include/clang/Basic/AttrDocs.td (working copy)<br class="">@@ -2812,3 +2812,97 @@<br class="">ensure that this class cannot be subclassed.<br class=""> }];<br class="">}<br class="">+<br class="">+def DocCatGeneric : DocumentationCategory<"Generic Attributes"> {<br class="">+ let Content = [{<br class="">+These attributes are suitable for passing arbitrary information from the code to<br class="">+a plugin or other clang based tools such as source code transformers, generators,<br class="">+collectors and similar. The attributes are not tied to any type of solution or<br class="">+predefined functionality and may be used in a variety of situations when a generic<br class="">+attribute suffice.<br class="">+ }];<br class="">+}<br class="">+<br class="">+def AnnotateDocs : Documentation {<br class="">+ let Category = DocCatGeneric;<br class="">+ let Content = [{<br class="">+The ``annotate`` attribute may be used to annotate any type of declarations or<br class="">+statements with arbitrary information that are propagated to the AST. The attribute<br class="">+takes one string parameter containing the annotation value. The content, format<br class="">+and the exact meaning of the value is up to the programmer to decide.<br class="">+<br class="">+C++11 spelling examples:<br class="">+<br class="">+.. code-block:: c++<br class="">+<br class="">+ class [[annotate("plain")]] Object<br class="">+ { . . . };<br class="">+<br class="">+ int main(int argc, char* argv[])<br class="">+ {<br class="">+ [[annotate("local_var")]] // Decl annotation<br class="">+ int n = 1 ;<br class="">+<br class="">+ // Multiple Stmt annotations<br class="">+ [[annotate("group-A"), annotate("opt-1:2")]]<br class="">+ switch(n)<br class="">+ { . . . }<br class="">+ return 0;<br class="">+ }<br class="">+<br class="">+Looking at the AST for the example above reveals that any annotated statements<br class="">+are wrapped into an AttributedStmt node together with the annotation attributes<br class="">+in comparison to annotated declarations where the annotation attributes are<br class="">+attached directly beneath the declaration node.<br class="">+<br class="">+.. code-block:: text<br class="">+<br class="">+ TranslationUnitDecl 0x345fb20 <<invalid sloc>> <invalid sloc><br class="">+ | . . .<br class="">+ |-CXXRecordDecl 0x34b9b58 <example.cpp:2:1, line:10:1> line:2:29 class Object definition<br class="">+ | |-AnnotateAttr 0x34b9c10 <col:9, col:25> "plain"<br class="">+ | |-CXXRecordDecl 0x34b9cb8 <col:1, col:29> col:29 implicit class Object<br class="">+ | |-AccessSpecDecl 0x34b9d50 <line:4:3, col:9> col:3 public<br class="">+ | ` . . .<br class="">+ `-FunctionDecl 0x34ba240 <line:12:1, line:28:1> line:12:5 main 'int (int, char **)'<br class="">+ |-ParmVarDecl 0x34ba020 <col:10, col:14> col:14 argc 'int'<br class="">+ |-ParmVarDecl 0x34ba130 <col:20, col:31> col:26 argv 'char **':'char **'<br class="">+ `-CompoundStmt 0x34ba7f0 <line:13:1, line:28:1><br class="">+ |-DeclStmt 0x34ba4d0 <line:15:2, col:12><br class="">+ | `-VarDecl 0x34ba400 <col:2, col:10> col:6 used n 'int' cinit<br class="">+ | |-IntegerLiteral 0x34ba4b0 <col:10> 'int' 1<br class="">+ | `-AnnotateAttr 0x34ba460 <line:14:4, col:24> "local_var"<br class="">+ |-AttributedStmt 0x34ba790 <line:17:2, line:26:2><br class="">+ | |-AnnotateAttr 0x34ba750 <line:17:25, col:43> "opt-1:2"<br class="">+ | |-AnnotateAttr 0x34ba770 <col:4, col:22> "group-A"<br class="">+ | `-SwitchStmt 0x34ba608 <line:18:2, line:26:2><br class="">+ | . . .<br class="">+ `-ReturnStmt 0x34ba7d8 <line:27:2, col:9><br class="">+ `-IntegerLiteral 0x34ba7b8 <col:9> 'int' 0<br class="">+<br class="">+The GNU spelling, ``__attribute((annotate("str")))``, is limited to annotating<br class="">+declarations but is at the same time a bit more relaxed on the allowed insertion<br class="">+points compared to the C++11 spelling that needs to be defined prior to any<br class="">+declaration or statement.<br class="">+<br class="">+In the example below the GNU-only insertion points are shown as __attr.<br class="">+<br class="">+.. code-block:: c++<br class="">+<br class="">+ void __attr function/method(int __attr n) __attr<br class="">+ int __attr n = 1;<br class="">+<br class="">+(Note that it is also possible to annotate arbitrary expressions using the GCC<br class="">+syntax ``int __builtin_annotation(int, "str")`` where the ``int`` is an integer<br class="">+of any compiler supported bit-width and with the return value set to the same<br class="">+as the parameter value. However, the annotation does not show up in the AST as<br class="">+an AnnotateAttr but as an ordinary CallExpr).<br class="">+<br class="">+The annotations of variable, function and method declarations (and expressions)<br class="">+are forwarded into IR during code generation using the LLVM annotation intrinsic<br class="">+functions or by adding the information to a global annotation table. The<br class="">+information added, in either case, are the annotation string, file name and<br class="">+line number of the declaration or expression. These IR annotations may be used<br class="">+by optimizers or other back-end tools.<br class="">+ }];<br class="">+}<br class=""><br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">~Aaron</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">An example demonstratiing the use and syntax of the updated attribute:<br class=""><br class=""> class [[annotate("plain")]] Object<br class=""> { . . . };<br class=""><br class=""> int main(int argc, char* argv[]) __attribute((annotate("entry-point")))<br class=""> {<br class=""> [[annotate("local_var")]] // Decl annotation<br class=""> int n = 1 ;<br class=""><br class=""> // Multiple Stmt annotations<br class=""> [[annotate("group-A"), annotate("opt-1:2")]]<br class=""> switch(n)<br class=""> { . . . }<br class=""> return 0;<br class=""> }<br class=""><br class="">Cheers,<br class="">Chris<br class=""><br class="">Modified:<br class=""> include/clang/Basic/Attr.td<br class=""> include/clang/Basic/AttrDocs.td<br class=""> lib/Sema/SemaStmtAttr.cpp<br class="">Added:<br class=""> test/SemaCXX/attr-annotate.cpp<br class=""><br class="">_______________________________________________<br class="">cfe-commits mailing list<br class=""><a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a></blockquote></div></blockquote></div><br class=""></body></html>