[PATCH] D90975: [clangd] Don't run clang-tidy AST traversal if there are no checks.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 8 23:44:20 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG053110b22aa9: [clangd] Don't run clang-tidy AST traversal if there are no checks. (authored by sammccall).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90975/new/
https://reviews.llvm.org/D90975
Files:
clang-tools-extra/clangd/ParsedAST.cpp
Index: clang-tools-extra/clangd/ParsedAST.cpp
===================================================================
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -303,9 +303,18 @@
CTContext->setASTContext(&Clang->getASTContext());
CTContext->setCurrentFile(Filename);
CTChecks = CTFactories.createChecks(CTContext.getPointer());
- ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
- const clang::Diagnostic &Info) {
- if (CTContext) {
+ llvm::erase_if(CTChecks, [&](const auto &Check) {
+ return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
+ });
+ Preprocessor *PP = &Clang->getPreprocessor();
+ for (const auto &Check : CTChecks) {
+ Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
+ Check->registerMatchers(&CTFinder);
+ }
+
+ if (!CTChecks.empty()) {
+ ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
+ const clang::Diagnostic &Info) {
std::string CheckName = CTContext->getCheckName(Info.getID());
bool IsClangTidyDiag = !CheckName.empty();
if (IsClangTidyDiag) {
@@ -330,17 +339,8 @@
return DiagnosticsEngine::Error;
}
}
- }
- return DiagLevel;
- });
- Preprocessor *PP = &Clang->getPreprocessor();
- for (const auto &Check : CTChecks) {
- if (!Check->isLanguageVersionSupported(CTContext->getLangOpts()))
- continue;
- // FIXME: the PP callbacks skip the entire preamble.
- // Checks that want to see #includes in the main file do not see them.
- Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
- Check->registerMatchers(&CTFinder);
+ return DiagLevel;
+ });
}
}
@@ -415,7 +415,7 @@
std::vector<Decl *> ParsedDecls = Action->takeTopLevelDecls();
// AST traversals should exclude the preamble, to avoid performance cliffs.
Clang->getASTContext().setTraversalScope(ParsedDecls);
- {
+ if (!CTChecks.empty()) {
// Run the AST-dependent part of the clang-tidy checks.
// (The preprocessor part ran already, via PPCallbacks).
trace::Span Tracer("ClangTidyMatch");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90975.303758.patch
Type: text/x-patch
Size: 2312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201109/70c4bb9c/attachment.bin>
More information about the cfe-commits
mailing list