Accommodate changes of LLVM 21 & 22 to fix builds (#985)

This commit is contained in:
Stephen Senran Zhang 2025-08-07 00:54:25 +08:00 committed by Fangrui Song
parent 44fb405d00
commit 4427527ed8
3 changed files with 23 additions and 4 deletions

View File

@ -116,11 +116,18 @@ std::unique_ptr<CompilerInvocation> buildCompilerInvocation(const std::string &m
args.insert(args.begin() + 1, std::begin(arr), std::end(arr));
}
#if (LLVM_VERSION_MAJOR == 21 && LLVM_VERSION_MINOR >= 1) || \
(LLVM_VERSION_MAJOR >= 22) // llvmorg-21-init-12923-g13e1a2cb2246
DiagnosticOptions DiagOpt;
#else
DiagnosticOptions *DiagOpt = new DiagnosticOptions;
#endif
IntrusiveRefCntPtr<DiagnosticsEngine> diags(CompilerInstance::createDiagnostics(
#if LLVM_VERSION_MAJOR >= 20
*vfs,
#endif
new DiagnosticOptions, new IgnoringDiagConsumer, true));
DiagOpt, new IgnoringDiagConsumer, true));
#if LLVM_VERSION_MAJOR < 12 // llvmorg-12-init-5498-g257b29715bb
driver::Driver d(args[0], llvm::sys::getDefaultTargetTriple(), *diags, vfs);
#else

View File

@ -350,7 +350,7 @@ public:
if (fd->getTemplatedDecl()->getKind() == Decl::CXXDeductionGuide)
continue;
}
if (auto *rd = dyn_cast<RecordDecl>(r.Declaration))
if (auto *rd = dyn_cast<CXXRecordDecl>(r.Declaration))
if (rd->isInjectedClassName())
continue;
auto nk = r.Declaration->getDeclName().getNameKind();

View File

@ -352,7 +352,13 @@ void buildPreamble(Session &session, CompilerInvocation &ci, IntrusiveRefCntPtr<
#if LLVM_VERSION_MAJOR >= 20
*fs,
#endif
&ci.getDiagnosticOpts(), &dc, false);
#if (LLVM_VERSION_MAJOR == 21 && LLVM_VERSION_MINOR >= 1) || \
(LLVM_VERSION_MAJOR >= 22) // llvmorg-21-init-12923-g13e1a2cb2246
ci.getDiagnosticOpts(),
#else
&ci.getDiagnosticOpts(),
#endif
&dc, false);
if (oldP) {
std::lock_guard lock(session.wfiles->mutex);
for (auto &include : oldP->includes)
@ -362,7 +368,13 @@ void buildPreamble(Session &session, CompilerInvocation &ci, IntrusiveRefCntPtr<
}
CclsPreambleCallbacks pc;
if (auto newPreamble = PrecompiledPreamble::Build(ci, buf.get(), bounds, *de, fs, session.pch, true,
if (auto newPreamble = PrecompiledPreamble::Build(ci, buf.get(), bounds,
#if LLVM_VERSION_MAJOR >= 22 // llvmorg-22-init-2136-gc7f343750744
de,
#else
*de,
#endif
fs, session.pch, true,
#if LLVM_VERSION_MAJOR >= 17 // llvmorg-17-init-4072-gcc929590ad30
"",
#endif