From: Sam McCall Date: Fri, 6 Nov 2020 22:38:08 +0000 (+0100) Subject: [clangd] Don't run clang-tidy AST traversal if there are no checks. X-Git-Tag: llvmorg-13-init~6749 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=053110b22aa93b1f7bccdb0dae9dea7f755b045c;p=platform%2Fupstream%2Fllvm.git [clangd] Don't run clang-tidy AST traversal if there are no checks. While here, clean up ParsedAST::build a bit: - remove FIXMEs that were fixed long ago by ReplayPreamble - remove redundant if, ClangTidyContext is not actually optional Differential Revision: https://reviews.llvm.org/D90975 --- diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 6ca9c4f..d3c14e6 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -303,9 +303,18 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, 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 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, 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 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, std::vector 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");