-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[APINotes] Introduce APINotes infrastructure in Clang Sema and Frontend #72907
Conversation
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.
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 Frontend.
@llvm/pr-subscribers-clang Author: Egor Zhdan (egorzhdan) ChangesThis 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:
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()),
|
You can test this locally with the following command:git-clang-format --diff f4c6947a18d5c07d5743eb435c2854e61804ad24 b8421b0570cc634e205e5b06d10997a802d5dd76 -- clang/include/clang/Frontend/CompilerInstance.h clang/include/clang/Sema/Sema.h clang/lib/Frontend/CompilerInstance.cpp clang/lib/Sema/Sema.cpp View the diff from clang-format here.diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e9872cdeb0..3ef8dac4fc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12198,9 +12198,11 @@ public:
/// Called on well-formed 'fail' clause.
OMPClause *ActOnOpenMPFailClause(SourceLocation StartLoc,
SourceLocation EndLoc);
- OMPClause *ActOnOpenMPFailClause(
- OpenMPClauseKind Kind, SourceLocation KindLoc,
- SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);
+ OMPClause *ActOnOpenMPFailClause(OpenMPClauseKind Kind,
+ SourceLocation KindLoc,
+ SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc);
/// Called on well-formed 'seq_cst' clause.
OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc,
|
The clang-format failure is unrelated to this patch. |
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.