From d417597a1172903e398f0177c5af0e40fb0d4356 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 --- src/indexer.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/indexer.cc b/src/indexer.cc index 5e3e2bd6..343b686a 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -23,6 +23,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -1159,10 +1160,28 @@ public: IndexFrontendAction(IndexParam ¶m) : 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); + } + }; + Preprocessor &PP = CI.getPreprocessor(); PP.addPPCallbacks( std::make_unique(PP.getSourceManager(), param)); - return std::make_unique(); + std::vector> Consumers; + Consumers.push_back(std::make_unique(param)); + Consumers.push_back(std::make_unique()); + return std::make_unique(std::move(Consumers)); } }; } // namespace @@ -1229,6 +1248,10 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, if (!CI) return {}; ok = false; + // Disable computing warnings which will be discarded anyway. + CI->getDiagnosticOpts().IgnoreWarnings = true; + // Enable IndexFrontendAction::shouldSkipFunctionBody. + CI->getFrontendOpts().SkipFunctionBodies = true; // -fparse-all-comments enables documentation in the indexer and in // code completion. CI->getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1; @@ -1245,6 +1268,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())