<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 2, 2017 at 4:55 AM, Dean Michael Berris <span dir="ltr"><<a href="mailto:dean.berris@gmail.com" target="_blank">dean.berris@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="gmail-"><br>
> On 2 Mar 2017, at 09:40, Anna Zaks <<a href="mailto:zaks.anna@gmail.com">zaks.anna@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Wed, Mar 1, 2017 at 2:25 PM, Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br>
> This sounds totally reasonable.<br>
><br>
> I have vague memories that there was some demand for a generic way to slap attributes on decls without changing the source code, but I don't remember who wanted that. I thought it had something to do with static analysis, so maybe Jordan or Anna know?<br>
><br>
> Correct. We have implemented such system for clang. We call it API Notes. It currently lives in the out-of-tree clang used by the Swift compiler (<a href="http://github.com/apple/swift-clang" rel="noreferrer" target="_blank">http://github.com/apple/<wbr>swift-clang</a>). It is not complete, for example, it lacks C++ support, but we've been using it in production for several years now.<br>
><br>
> Doug has sent out an email about this and other out-of-tree changes trying to figure out if the community has interest in these additions. Here is the thread, it mainly discusses API Notes:<br>
><br>
> <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046335.html" rel="noreferrer" target="_blank">http://lists.llvm.org/<wbr>pipermail/cfe-dev/2015-<wbr>December/046335.html</a><br>
<br>
</span>Thanks for the pointer Anna -- I'll go have a read about this.<br>
<br>
Maybe later on we can generalise based on experience from swift to inform the design/use-cases if this will ever be done in clang.<br>
<br></blockquote><div><br></div><div>Just to be 100% clear, API Notes is a <b>clang</b> <b>feature</b> it's used by the Swift project to support interoperability between Swift and C/ObjC. (For example, to store knowledge about how C APIs should be imported into Swift.) The Swift project uses a clone of llvm/clang. The clone is auto-synced with top-of-tree llvm/clang but contains several features that are currently only used by the Swift project.</div><div><br></div><div>Here is the description of API Notes from Doug's email:</div><div><pre style="white-space:pre-wrap;color:rgb(0,0,0)">API notes solve a not-uncommon problem: we invent some new Clang attribute that would be beneficial to add to some declarations in system headers (e.g., adding a ‘noreturn’ attribute to the C ‘exit’ function), but we can’t go around and fix all of the system headers everywhere. With API notes, we can write a separate YAML file that states that we want to add ‘noreturn’ to the ‘exit’ function: when we feed that YAML file into Clang as part of normal compilation (via a command-line option), Clang will add ‘noreturn’ to the ‘exit’ function when it parses the declaration of ‘exit’. Personally, I don’t like API notes—even with our optimizations, it’s inefficient in compile time and it takes the “truth” out of the headers—but I can see the wider use cases. If the Clang community wants this feature, I can prepare a proper proposal; if not, we’ll keep this code in the Swift clone of Clang and delete it if Swift ever stops needing it.</pre><pre><div style="color:rgb(34,34,34);white-space:normal;font-family:arial,sans-serif">I think API notes can be used by other clients in clang, such a the static analyzer. It seems that it would be directly applicable to the scenario you describe as well. If so, I would propose to merge API Notes into mainline clang.</div><div style="color:rgb(0,0,0);white-space:pre-wrap"><br></div><div><font face="arial, sans-serif"><span style="white-space:normal">Even though Doug mentioned (in Dec 2015) that the Swift clone might delete this functionality in the future if API Notes are not needed any more, in practice, we see that the Swift project use cases for API Notes are expanding not shrinking.</span></font><font color="#000000"><span style="white-space:pre-wrap"><br></span></font></div></pre></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Cheers<br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
-- Dean<br>
<br>
</font></span></blockquote></div><br></div></div>