[clang] [Clang][HTO] Add clang attribute for propagating llvm-level information (PR #83059)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 28 06:29:39 PST 2024


erichkeane wrote:

> > Hm actually reopening, the metadata isn't emitted if the defnition isn't available [e.g. for `extern int X;` when given an annotation
> 
> That seems like a bug (so long as the declaration is actually emitted to LLVM IR at all).
> 
> > @AaronBallman @erichkeane, do you have any suggestions for paths forward, for use cases where it is guaranteed that the attribute is valid and the user (or perhaps more specifically, another Clang-tool) needs to provide information to LLVM through Clang AST/source.
> 
> If it's a Clang-based tool, that might open up other options. I think it could be reasonable to have an internal-use-only Clang attribute (one with no `Spelling` so users have no way to access it) that wraps LLVM IR attributes. You could use `MySpecialLLVMAttr::CreateImplicit()` to create the attributes as-needed from within the tool, rather than modifying source code and feeding it in to the compiler. Would that perhaps be workable for you? (No idea what @erichkeane thinks of this idea, but if we went this route, I would want a nice comment on the attribute definition explaining why it intentionally has no spelling so nobody comes along later and adds a spelling for it without realizing the concerns.)

I think I'd rather fix the extern declaration issues first, I'm guessing we just didn't add it to somewhere.

As far as the 'spelling-less' attribute, I'm not really sure how usable that would be, but I've done that trick in the past for a downstream.  Its probably OK, though definitely something we need to make sure no one touches.

https://github.com/llvm/llvm-project/pull/83059


More information about the cfe-commits mailing list