llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Egor Zhdan (egorzhdan) <details> <summary>Changes</summary> This upstreams more of the Clang API Notes functionality that is currently implemented in the Apple fork: https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes This adds the initial Clang APINotes infrastructure to Clang Sema and Clang Frontend. There will shortly be a follow-up patch with the actual usages of this API. I'm splitting these changes into separate PRs to keep the diffs easier to review. --- Full diff: https://github.com/llvm/llvm-project/pull/72907.diff 6 Files Affected: - (modified) clang/include/clang/Frontend/CompilerInstance.h (+5) - (modified) clang/include/clang/Sema/Sema.h (+2) - (modified) clang/lib/Frontend/CMakeLists.txt (+1) - (modified) clang/lib/Frontend/CompilerInstance.cpp (+4) - (modified) clang/lib/Sema/CMakeLists.txt (+1) - (modified) clang/lib/Sema/Sema.cpp (+2-1) ``````````diff diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index d26a452cf94cc3b..ac2f940769fbe90 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -304,6 +304,11 @@ class CompilerInstance : public ModuleLoader { return Invocation->getHeaderSearchOptsPtr(); } + APINotesOptions &getAPINotesOpts() { return Invocation->getAPINotesOpts(); } + const APINotesOptions &getAPINotesOpts() const { + return Invocation->getAPINotesOpts(); + } + LangOptions &getLangOpts() { return Invocation->getLangOpts(); } const LangOptions &getLangOpts() const { return Invocation->getLangOpts(); } diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 63a9f9d4cffe2f2..e9872cdeb0b2522 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_SEMA_SEMA_H #define LLVM_CLANG_SEMA_SEMA_H +#include "clang/APINotes/APINotesManager.h" #include "clang/AST/ASTConcept.h" #include "clang/AST/ASTFwd.h" #include "clang/AST/Attr.h" @@ -408,6 +409,7 @@ class Sema final { ASTConsumer &Consumer; DiagnosticsEngine &Diags; SourceManager &SourceMgr; + api_notes::APINotesManager APINotes; /// Flag indicating whether or not to collect detailed statistics. bool CollectStats; diff --git a/clang/lib/Frontend/CMakeLists.txt b/clang/lib/Frontend/CMakeLists.txt index 1e5f0a859dfd568..a91666720884591 100644 --- a/clang/lib/Frontend/CMakeLists.txt +++ b/clang/lib/Frontend/CMakeLists.txt @@ -48,6 +48,7 @@ add_clang_library(clangFrontend intrinsics_gen LINK_LIBS + clangAPINotes clangAST clangBasic clangDriver diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index d749195585eca5b..be5b38d6110fc3b 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -747,6 +747,10 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer) { TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(), TUKind, CompletionConsumer)); + + // Set up API notes. + TheSema->APINotes.setSwiftVersion(getAPINotesOpts().SwiftVersion); + // Attach the external sema source if there is any. if (ExternalSemaSrc) { TheSema->addExternalSource(ExternalSemaSrc.get()); diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt index d3d403c1d5d79ef..1856a88e9a3271a 100644 --- a/clang/lib/Sema/CMakeLists.txt +++ b/clang/lib/Sema/CMakeLists.txt @@ -74,6 +74,7 @@ add_clang_library(clangSema ClangDriverOptions LINK_LIBS + clangAPINotes clangAST clangAnalysis clangBasic diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index d7d8d2eaa37e1d6..9771aaa2f3b0371 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -191,7 +191,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, : ExternalSource(nullptr), CurFPFeatures(pp.getLangOpts()), LangOpts(pp.getLangOpts()), PP(pp), Context(ctxt), Consumer(consumer), Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()), - CollectStats(false), CodeCompleter(CodeCompleter), CurContext(nullptr), + APINotes(SourceMgr, LangOpts), CollectStats(false), + CodeCompleter(CodeCompleter), CurContext(nullptr), OriginalLexicalContext(nullptr), MSStructPragmaOn(false), MSPointerToMemberRepresentationMethod( LangOpts.getMSPointerToMemberRepresentationMethod()), `````````` </details> https://github.com/llvm/llvm-project/pull/72907 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits