Skip to content

Commit b3d694b

Browse files
committed
indexer: disable warnings and skip processed function bodies
Adapt clang rC370337: removal of createIndexingAction and WrappingIndexAction
1 parent 65f86d0 commit b3d694b

3 files changed

Lines changed: 49 additions & 11 deletions

File tree

src/clang_tu.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
8585
if (ci) {
8686
ci->getDiagnosticOpts().IgnoreWarnings = true;
8787
ci->getFrontendOpts().DisableFree = false;
88+
// Enable IndexFrontendAction::shouldSkipFunctionBody.
89+
ci->getFrontendOpts().SkipFunctionBodies = true;
8890
ci->getLangOpts()->SpellChecking = false;
8991
auto &isec = ci->getFrontendOpts().Inputs;
9092
if (isec.size())

src/indexer.cc

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <clang/AST/AST.h>
1313
#include <clang/Basic/TargetInfo.h>
1414
#include <clang/Frontend/FrontendAction.h>
15+
#include <clang/Frontend/MultiplexConsumer.h>
1516
#include <clang/Index/IndexDataConsumer.h>
1617
#include <clang/Index/IndexingAction.h>
1718
#include <clang/Index/USRGeneration.h>
@@ -1154,16 +1155,43 @@ class IndexPPCallbacks : public PPCallbacks {
11541155
};
11551156

11561157
class IndexFrontendAction : public ASTFrontendAction {
1158+
std::shared_ptr<IndexDataConsumer> dataConsumer;
1159+
const index::IndexingOptions &indexOpts;
11571160
IndexParam &param;
11581161

11591162
public:
1160-
IndexFrontendAction(IndexParam &param) : param(param) {}
1161-
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
1162-
StringRef InFile) override {
1163-
Preprocessor &PP = CI.getPreprocessor();
1164-
PP.addPPCallbacks(
1165-
std::make_unique<IndexPPCallbacks>(PP.getSourceManager(), param));
1166-
return std::make_unique<ASTConsumer>();
1163+
IndexFrontendAction(std::shared_ptr<IndexDataConsumer> dataConsumer,
1164+
const index::IndexingOptions &indexOpts,
1165+
IndexParam &param)
1166+
: dataConsumer(std::move(dataConsumer)), indexOpts(indexOpts),
1167+
param(param) {}
1168+
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &ci,
1169+
StringRef inFile) override {
1170+
class SkipProcessed : public ASTConsumer {
1171+
IndexParam &param;
1172+
const ASTContext *ctx = nullptr;
1173+
1174+
public:
1175+
SkipProcessed(IndexParam &param) : param(param) {}
1176+
void Initialize(ASTContext &ctx) override { this->ctx = &ctx; }
1177+
bool shouldSkipFunctionBody(Decl *d) override {
1178+
const SourceManager &sm = ctx->getSourceManager();
1179+
FileID fid = sm.getFileID(sm.getExpansionLoc(d->getLocation()));
1180+
return !(g_config->index.multiVersion && param.useMultiVersion(fid)) &&
1181+
!param.consumeFile(fid);
1182+
}
1183+
};
1184+
1185+
std::shared_ptr<Preprocessor> pp = ci.getPreprocessorPtr();
1186+
pp->addPPCallbacks(
1187+
std::make_unique<IndexPPCallbacks>(pp->getSourceManager(), param));
1188+
std::vector<std::unique_ptr<ASTConsumer>> consumers;
1189+
consumers.push_back(std::make_unique<SkipProcessed>(param));
1190+
#if LLVM_VERSION_MAJOR >= 10 // rC370337
1191+
consumers.push_back(index::createIndexingASTConsumer(
1192+
dataConsumer, indexOpts, std::move(pp)));
1193+
#endif
1194+
return std::make_unique<MultiplexConsumer>(std::move(consumers));
11671195
}
11681196
};
11691197
} // namespace
@@ -1248,6 +1276,7 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
12481276
auto clang = std::make_unique<CompilerInstance>(pch);
12491277
clang->setInvocation(std::move(ci));
12501278
clang->createDiagnostics(&dc, false);
1279+
clang->getDiagnostics().setIgnoreAllWarnings(true);
12511280
clang->setTarget(TargetInfo::CreateTargetInfo(
12521281
clang->getDiagnostics(), clang->getInvocation().TargetOpts));
12531282
if (!clang->hasTarget())
@@ -1263,7 +1292,6 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
12631292
clang->getFileManager(), true));
12641293

12651294
IndexParam param(*vfs, no_linkage);
1266-
auto dataConsumer = std::make_shared<IndexDataConsumer>(param);
12671295

12681296
index::IndexingOptions indexOpts;
12691297
indexOpts.SystemSymbolFilter =
@@ -1279,8 +1307,16 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
12791307
#endif
12801308
}
12811309

1282-
std::unique_ptr<FrontendAction> action = createIndexingAction(
1283-
dataConsumer, indexOpts, std::make_unique<IndexFrontendAction>(param));
1310+
#if LLVM_VERSION_MAJOR >= 10 // rC370337
1311+
auto action = std::make_unique<IndexFrontendAction>(
1312+
std::make_shared<IndexDataConsumer>(param), indexOpts, param);
1313+
#else
1314+
auto dataConsumer = std::make_shared<IndexDataConsumer>(param);
1315+
auto action = createIndexingAction(
1316+
dataConsumer, indexOpts,
1317+
std::make_unique<IndexFrontendAction>(dataConsumer, indexOpts, param));
1318+
#endif
1319+
12841320
std::string reason;
12851321
{
12861322
llvm::CrashRecoveryContext crc;

src/sema_manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ void *completionMain(void *manager_) {
467467
fOpts.CodeCompletionAt.FileName = task->path;
468468
fOpts.CodeCompletionAt.Line = task->position.line + 1;
469469
fOpts.CodeCompletionAt.Column = task->position.character + 1;
470-
fOpts.SkipFunctionBodies = true;
471470
ci->getLangOpts()->CommentOpts.ParseAllComments = true;
472471

473472
DiagnosticConsumer dc;
@@ -573,6 +572,7 @@ void *diagnosticMain(void *manager_) {
573572
if (lookupExtension(session->file.filename).second)
574573
ci->getDiagnosticOpts().Warnings.push_back("no-unused-function");
575574
ci->getDiagnosticOpts().IgnoreWarnings = false;
575+
ci->getFrontendOpts().SkipFunctionBodies = false;
576576
ci->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking;
577577
StoreDiags dc(task.path);
578578
std::string content = manager->wfiles->getContent(task.path);

0 commit comments

Comments
 (0)