<div dir="ltr"><div><div><div><div>Hi!<br><br></div>I wanted to revive the discussion on adding API notes feature to Clang. <br><br></div></div><div><b>The description of the feature from the original discussion</b><br><br>"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’."</div><div><br>The old discussion can be found here: <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046335.html">http://lists.llvm.org/pipermail/cfe-dev/2015-December/046335.html</a><br><br></div><b>The summary of the discussion</b><br><br></div><div>* It would be useful for the static analyzer to attach additional info to the functions<br>* There were already other trials to get similar feature working, see <a href="https://reviews.llvm.org/D13731">https://reviews.llvm.org/D13731</a><br></div><div>* Anna has a nice summary what is the problem with augmented declarations: <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046378.html">http://lists.llvm.org/pipermail/cfe-dev/2015-December/046378.html</a><br></div><div>* C++ support is requested by the community, this is missing right now. <br></div><div>* Wider range of annotation support is missing. It is also requested by the community. <br></div><div>* Parameter annotations are supported<br></div><div>* One of the concerns is the performance<br><br></div><div><b>The case for adding API Notes</b><br><br></div><div>* Importing annotations from external source looks to be an interesting feature for the community<br></div><div>* Sean presented some API checkers which works based on special annotations: <a href="http://llvm.org/devmtg/2017-03//2017/02/20/accepted-sessions.html#29">http://llvm.org/devmtg/2017-03//2017/02/20/accepted-sessions.html#29</a><br></div><div>* Similar feature can be used to provide fake implementations for functions. It could help to finish a half done feature of the Static Analyzer that was implemented during a GSoC project: <a href="https://www.google-melange.com/archive/gsoc/2014/orgs/llvm/projects/xazax.html">https://www.google-melange.com/archive/gsoc/2014/orgs/llvm/projects/xazax.html</a><br>* Performance might be crucial for regular compilation, but less of a problem for the Clang Static Analyzer which tends to be slower than compilations, so it is less likely to be bottlenecked by this phase<br></div><div>* It would also be possible to import sanitizer/optimizer/codegen related annotations<br></div><div><br></div><div><b>Proposed roadmap</b><br></div><div><br></div><div>* Commit the feature as is<br></div><div>* Extend it with C++ support (namespaces, overloading, templates..)<br></div><div>* Extend it with additional annotations, and attaching custom data (like fake function bodies)<br></div><div><br></div><div>What do you think? What are the main concerns with this feature?<br><br></div><div>Regards,<br></div><div>Gábor<br></div><div><br></div></div>