[cfe-dev] [XRay] RFC: Adding -fxray-{always, never}-instrument=... to Clang

Anna Zaks via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 2 09:14:56 PST 2017


On Thu, Mar 2, 2017 at 4:55 AM, Dean Michael Berris <dean.berris at gmail.com>
wrote:

>
> > On 2 Mar 2017, at 09:40, Anna Zaks <zaks.anna at gmail.com> wrote:
> >
> >
> >
> > On Wed, Mar 1, 2017 at 2:25 PM, Reid Kleckner <rnk at google.com> wrote:
> > This sounds totally reasonable.
> >
> > 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?
> >
> > 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 (http://github.com/apple/swift-clang). It is not complete, for
> example, it lacks C++ support, but we've been using it in production for
> several years now.
> >
> > 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:
> >
> > http://lists.llvm.org/pipermail/cfe-dev/2015-December/046335.html
>
> Thanks for the pointer Anna -- I'll go have a read about this.
>
> 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.
>
>
Just to be 100% clear, API Notes is a *clang* *feature* 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.

Here is the description of API Notes from Doug's email:

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.

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.

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.

Cheers
>
> -- Dean
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170302/d040054b/attachment.html>


More information about the cfe-dev mailing list