[cfe-dev] Adding Support for APINotes

James Y Knight via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 12 12:29:37 PDT 2020


On Mon, Oct 12, 2020 at 12:46 PM Gábor Márton <martongabesz at gmail.com>
wrote:

> +1 for separating the Swift specific Sema logic the way you described.
> However, there are valuable implementations in lib/APINotes/*
> <https://github.com/apple/llvm-project/tree/apple/main/clang/lib/APINotes> which
> we could use for a generic APINotes framework in Clang. For instance,
> APINotesManager::findAPINotes
> <https://github.com/apple/llvm-project/blob/apple/main/clang/lib/APINotes/APINotesManager.cpp#L325> encapsulates
> the logic for finding the APINotes files, this seems to be totally
> independent from Swift.
>

Do you think that will actually be useful to the static analyzer use-case?
I'd expect that in most use-cases, you'd want to provide the changes via
some mechanism other than searching for a file named "APINotes.apinotes" in
the same directory as you found the header. Other than for Swift with Apple
frameworks, it seems likely to be pretty rare that the producer of a
particular library would be the same entity providing a file of extra
attributes on the side?

Also, I believe that particular function is unused in Swift. AFAICT, Swift
only uses the modules-based apinotes loading (loadCurrentModuleAPINotes),
not the header-path-based loading (that is: it passes "-fapinotes-modules"
to its internal Clang invocation, not "-fapinotes").

A side note: ASTMutationListener
> <https://clang.llvm.org/doxygen/classclang_1_1ASTMutationListener.html> is
> the interface which notifies any consumers when an AST node is changed
> after its creation. I think we should notify all clients once we add a new
> APINote Attribute (e.g. see AddedAttributeToRecord
> <https://clang.llvm.org/doxygen/classclang_1_1ASTMutationListener.html#abd04809c814e5ea2af681465004f32fe>),
> shouldn't we?
>

I wouldn't think so, since this mechanism modifies the nodes as part of
their initial creation, not as a subsequent mutation?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20201012/0e7b5f67/attachment.html>


More information about the cfe-dev mailing list