From 3865a0944739fff23fdaa53ec287d315f4be6edb Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 21 Aug 2019 18:59:41 -0700 Subject: [PATCH] indexer: disable warnings and skip processed function bodies Adapt clang rC370337: removal of createIndexingAction and WrappingIndexAction --- src/clang_tu.cc | 2 ++ src/indexer.cc | 56 +++++++++++++++++++++++++++++++++++++-------- src/sema_manager.cc | 2 +- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 25b276d6..1132d10d 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -96,6 +96,8 @@ buildCompilerInvocation(const std::string &main, std::vector args, if (ci) { ci->getDiagnosticOpts().IgnoreWarnings = true; ci->getFrontendOpts().DisableFree = false; + // Enable IndexFrontendAction::shouldSkipFunctionBody. + ci->getFrontendOpts().SkipFunctionBodies = true; ci->getLangOpts()->SpellChecking = false; auto &isec = ci->getFrontendOpts().Inputs; if (isec.size()) diff --git a/src/indexer.cc b/src/indexer.cc index 94a31e5e..6446c2a2 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -23,6 +23,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -1163,16 +1164,43 @@ public: }; class IndexFrontendAction : public ASTFrontendAction { + std::shared_ptr dataConsumer; + const index::IndexingOptions &indexOpts; IndexParam ¶m; public: - IndexFrontendAction(IndexParam ¶m) : param(param) {} - std::unique_ptr CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override { - Preprocessor &PP = CI.getPreprocessor(); - PP.addPPCallbacks( - std::make_unique(PP.getSourceManager(), param)); - return std::make_unique(); + IndexFrontendAction(std::shared_ptr dataConsumer, + const index::IndexingOptions &indexOpts, + IndexParam ¶m) + : dataConsumer(std::move(dataConsumer)), indexOpts(indexOpts), + param(param) {} + std::unique_ptr CreateASTConsumer(CompilerInstance &ci, + StringRef inFile) override { + class SkipProcessed : public ASTConsumer { + IndexParam ¶m; + const ASTContext *ctx = nullptr; + + public: + SkipProcessed(IndexParam ¶m) : param(param) {} + void Initialize(ASTContext &ctx) override { this->ctx = &ctx; } + bool shouldSkipFunctionBody(Decl *d) override { + const SourceManager &sm = ctx->getSourceManager(); + FileID fid = sm.getFileID(sm.getExpansionLoc(d->getLocation())); + return !(g_config->index.multiVersion && param.useMultiVersion(fid)) && + !param.consumeFile(fid); + } + }; + + std::shared_ptr pp = ci.getPreprocessorPtr(); + pp->addPPCallbacks( + std::make_unique(pp->getSourceManager(), param)); + std::vector> consumers; + consumers.push_back(std::make_unique(param)); +#if LLVM_VERSION_MAJOR >= 10 // rC370337 + consumers.push_back(index::createIndexingASTConsumer( + dataConsumer, indexOpts, std::move(pp))); +#endif + return std::make_unique(std::move(consumers)); } }; } // namespace @@ -1257,6 +1285,7 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, auto clang = std::make_unique(pch); clang->setInvocation(std::move(ci)); clang->createDiagnostics(&dc, false); + clang->getDiagnostics().setIgnoreAllWarnings(true); clang->setTarget(TargetInfo::CreateTargetInfo( clang->getDiagnostics(), clang->getInvocation().TargetOpts)); if (!clang->hasTarget()) @@ -1272,7 +1301,6 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, clang->getFileManager(), true)); IndexParam param(*vfs, no_linkage); - auto dataConsumer = std::make_shared(param); index::IndexingOptions indexOpts; indexOpts.SystemSymbolFilter = @@ -1288,8 +1316,16 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, #endif } - std::unique_ptr action = createIndexingAction( - dataConsumer, indexOpts, std::make_unique(param)); +#if LLVM_VERSION_MAJOR >= 10 // rC370337 + auto action = std::make_unique( + std::make_shared(param), indexOpts, param); +#else + auto dataConsumer = std::make_shared(param); + auto action = createIndexingAction( + dataConsumer, indexOpts, + std::make_unique(dataConsumer, indexOpts, param)); +#endif + std::string reason; { llvm::CrashRecoveryContext crc; diff --git a/src/sema_manager.cc b/src/sema_manager.cc index a43f788f..7b5c92c2 100644 --- a/src/sema_manager.cc +++ b/src/sema_manager.cc @@ -478,7 +478,6 @@ void *completionMain(void *manager_) { fOpts.CodeCompletionAt.FileName = task->path; fOpts.CodeCompletionAt.Line = task->position.line + 1; fOpts.CodeCompletionAt.Column = task->position.character + 1; - fOpts.SkipFunctionBodies = true; ci->getLangOpts()->CommentOpts.ParseAllComments = true; DiagnosticConsumer dc; @@ -584,6 +583,7 @@ void *diagnosticMain(void *manager_) { if (lookupExtension(session->file.filename).second) ci->getDiagnosticOpts().Warnings.push_back("no-unused-function"); ci->getDiagnosticOpts().IgnoreWarnings = false; + ci->getFrontendOpts().SkipFunctionBodies = false; ci->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking; StoreDiags dc(task.path); std::string content = manager->wfiles->getContent(task.path);