Compare commits

...

2 Commits

Author SHA1 Message Date
Fangrui Song
3799e38920 Adapt llvmorg-21 changes: clang::CompilerInstance and llvm::PointerUnion 2025-05-11 23:37:30 -07:00
Fangrui Song
962c0e72b4 Clear index requests upon "exit"
to make indexers stop in time. This is especially relevant when there
are many initial index requests.
2025-01-28 10:34:19 -08:00
3 changed files with 39 additions and 1 deletions

View File

@ -377,10 +377,17 @@ const Decl *getAdjustedDecl(const Decl *d) {
if (!s->isExplicitSpecialization()) {
llvm::PointerUnion<ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl *> result =
s->getSpecializedTemplateOrPartial();
if (result.is<ClassTemplateDecl *>())
#if LLVM_VERSION_MAJOR >= 21
if (auto *ctd = dyn_cast<ClassTemplateDecl *>(result))
d = ctd;
else
d = cast<ClassTemplatePartialSpecializationDecl *>(result);
#else
if (isa<ClassTemplateDecl *>(result))
d = result.get<ClassTemplateDecl *>();
else
d = result.get<ClassTemplatePartialSpecializationDecl *>();
#endif
continue;
}
} else if (auto *d1 = r->getInstantiatedFromMemberClass()) {
@ -964,10 +971,17 @@ public:
else if (auto *sd = dyn_cast<ClassTemplateSpecializationDecl>(rd)) {
llvm::PointerUnion<ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl *> result =
sd->getSpecializedTemplateOrPartial();
#if LLVM_VERSION_MAJOR >= 21
if (auto *ctd = dyn_cast<ClassTemplateDecl *>(result))
d1 = ctd;
else
d1 = cast<ClassTemplatePartialSpecializationDecl *>(result);
#else
if (result.is<ClassTemplateDecl *>())
d1 = result.get<ClassTemplateDecl *>();
else
d1 = result.get<ClassTemplatePartialSpecializationDecl *>();
#endif
} else
d1 = rd->getInstantiatedFromMemberClass();
@ -1241,15 +1255,23 @@ IndexResult index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, const st
}
IndexDiags dc;
#if LLVM_VERSION_MAJOR >= 21
auto clang = std::make_unique<CompilerInstance>(std::move(ci), pch);
#else
auto clang = std::make_unique<CompilerInstance>(pch);
clang->setInvocation(std::move(ci));
#endif
clang->createDiagnostics(
#if LLVM_VERSION_MAJOR >= 20
*fs,
#endif
&dc, false);
clang->getDiagnostics().setIgnoreAllWarnings(true);
#if LLVM_VERSION_MAJOR >= 21
clang->setTarget(TargetInfo::CreateTargetInfo(clang->getDiagnostics(), clang->getTargetOpts()));
#else
clang->setTarget(TargetInfo::CreateTargetInfo(clang->getDiagnostics(), clang->getInvocation().TargetOpts));
#endif
if (!clang->hasTarget())
return {};
clang->getPreprocessorOpts().RetainRemappedFileBuffers = true;

View File

@ -684,6 +684,14 @@ void mainLoop() {
path2backlog[ex.path].push_back(&backlog.back());
}
// If the "exit" notification has been received, clear all index requests
// to make indexers stop in time.
if (g_quit.load(std::memory_order_relaxed)) {
index_request->apply([&](std::deque<IndexRequest> &q) {
q.clear();
});
}
bool indexed = false;
for (int i = 20; i--;) {
std::optional<IndexUpdate> update = on_indexed->tryPopFront();

View File

@ -261,14 +261,22 @@ std::unique_ptr<CompilerInstance> buildCompilerInstance(Session &session, std::u
else
ci->getPreprocessorOpts().addRemappedFile(main, buf.get());
#if LLVM_VERSION_MAJOR >= 21
auto clang = std::make_unique<CompilerInstance>(std::move(ci), session.pch);
#else
auto clang = std::make_unique<CompilerInstance>(session.pch);
clang->setInvocation(std::move(ci));
#endif
clang->createDiagnostics(
#if LLVM_VERSION_MAJOR >= 20
*fs,
#endif
&dc, false);
#if LLVM_VERSION_MAJOR >= 21
clang->setTarget(TargetInfo::CreateTargetInfo(clang->getDiagnostics(), clang->getTargetOpts()));
#else
clang->setTarget(TargetInfo::CreateTargetInfo(clang->getDiagnostics(), clang->getInvocation().TargetOpts));
#endif
if (!clang->hasTarget())
return nullptr;
clang->getPreprocessorOpts().RetainRemappedFileBuffers = true;