|
| 1 | +From d31cc9f07668a91c892d5f13367b9a1e773fbe2b Mon Sep 17 00:00:00 2001 |
| 2 | +From: Fangrui Song <i@maskray.me> |
| 3 | +Date: Sat, 15 Nov 2025 13:37:03 -0800 |
| 4 | +Subject: [PATCH] Adapt llvm 22 changes |
| 5 | + |
| 6 | +Type::Elaborated is removed by llvmorg-22-init-3166-g91cdd35008e9 |
| 7 | + |
| 8 | +llvm::sys::fs and clang functions are changed due to |
| 9 | +https://discourse.llvm.org/t/rfc-file-system-sandboxing-in-clang-llvm/88791 |
| 10 | +--- |
| 11 | + src/indexer.cc | 9 ++++++++- |
| 12 | + src/messages/initialize.cc | 4 ++++ |
| 13 | + src/sema_manager.cc | 7 ++++++- |
| 14 | + 3 files changed, 18 insertions(+), 2 deletions(-) |
| 15 | + |
| 16 | +diff --git a/src/indexer.cc b/src/indexer.cc |
| 17 | +index 6d32077e1..bd4da48db 100644 |
| 18 | +--- a/src/indexer.cc |
| 19 | ++++ b/src/indexer.cc |
| 20 | +@@ -364,9 +364,11 @@ const Decl *getTypeDecl(QualType t, bool *specialization = nullptr) { |
| 21 | + |
| 22 | + // FIXME: Template type parameters! |
| 23 | + |
| 24 | ++#if LLVM_VERSION_MAJOR < 22 // llvmorg-22-init-3166-g91cdd35008e9 |
| 25 | + case Type::Elaborated: |
| 26 | + tp = cast<ElaboratedType>(tp)->getNamedType().getTypePtrOrNull(); |
| 27 | + goto try_again; |
| 28 | ++#endif |
| 29 | + |
| 30 | + default: |
| 31 | + break; |
| 32 | +@@ -1266,7 +1268,7 @@ IndexResult index(WorkingFiles *wfiles, VFS *vfs, const std::string &opt_wdir, c |
| 33 | + clang->setInvocation(std::move(ci)); |
| 34 | + #endif |
| 35 | + clang->createDiagnostics( |
| 36 | +-#if LLVM_VERSION_MAJOR >= 20 |
| 37 | ++#if LLVM_VERSION_MAJOR >= 20 && LLVM_VERSION_MAJOR < 22 |
| 38 | + *fs, |
| 39 | + #endif |
| 40 | + &dc, false); |
| 41 | +@@ -1279,7 +1281,12 @@ IndexResult index(WorkingFiles *wfiles, VFS *vfs, const std::string &opt_wdir, c |
| 42 | + if (!clang->hasTarget()) |
| 43 | + return {}; |
| 44 | + clang->getPreprocessorOpts().RetainRemappedFileBuffers = true; |
| 45 | ++#if LLVM_VERSION_MAJOR >= 22 |
| 46 | ++ clang->setVirtualFileSystem(fs); |
| 47 | ++ clang->createFileManager(); |
| 48 | ++#else |
| 49 | + clang->createFileManager(fs); |
| 50 | ++#endif |
| 51 | + clang->setSourceManager(new SourceManager(clang->getDiagnostics(), clang->getFileManager(), true)); |
| 52 | + |
| 53 | + IndexParam param(*vfs, no_linkage); |
| 54 | +diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc |
| 55 | +index 03e1b0045..4db64710a 100644 |
| 56 | +--- a/src/messages/initialize.cc |
| 57 | ++++ b/src/messages/initialize.cc |
| 58 | +@@ -345,7 +345,11 @@ void do_initialize(MessageHandler *m, InitializeParam ¶m, ReplyOnce &reply) |
| 59 | + |
| 60 | + if (g_config->cache.directory.size()) { |
| 61 | + SmallString<256> path(g_config->cache.directory); |
| 62 | ++#if LLVM_VERSION_MAJOR >= 22 |
| 63 | ++ sys::path::make_absolute(project_path, path); |
| 64 | ++#else |
| 65 | + sys::fs::make_absolute(project_path, path); |
| 66 | ++#endif |
| 67 | + // Use upper case for the Driver letter on Windows. |
| 68 | + g_config->cache.directory = normalizePath(path.str()); |
| 69 | + ensureEndsInSlash(g_config->cache.directory); |
| 70 | +diff --git a/src/sema_manager.cc b/src/sema_manager.cc |
| 71 | +index 9ae1c132a..222d110f8 100644 |
| 72 | +--- a/src/sema_manager.cc |
| 73 | ++++ b/src/sema_manager.cc |
| 74 | +@@ -268,7 +268,7 @@ std::unique_ptr<CompilerInstance> buildCompilerInstance(Session &session, std::u |
| 75 | + clang->setInvocation(std::move(ci)); |
| 76 | + #endif |
| 77 | + clang->createDiagnostics( |
| 78 | +-#if LLVM_VERSION_MAJOR >= 20 |
| 79 | ++#if LLVM_VERSION_MAJOR >= 20 && LLVM_VERSION_MAJOR < 22 |
| 80 | + *fs, |
| 81 | + #endif |
| 82 | + &dc, false); |
| 83 | +@@ -283,7 +283,12 @@ std::unique_ptr<CompilerInstance> buildCompilerInstance(Session &session, std::u |
| 84 | + // Construct SourceManager with UserFilesAreVolatile: true because otherwise |
| 85 | + // RequiresNullTerminator: true may cause out-of-bounds read when a file is |
| 86 | + // mmap'ed but is saved concurrently. |
| 87 | ++#if LLVM_VERSION_MAJOR >= 22 |
| 88 | ++ clang->setVirtualFileSystem(fs); |
| 89 | ++ clang->createFileManager(); |
| 90 | ++#else |
| 91 | + clang->createFileManager(fs); |
| 92 | ++#endif |
| 93 | + clang->setSourceManager(new SourceManager(clang->getDiagnostics(), clang->getFileManager(), true)); |
| 94 | + auto &isec = clang->getFrontendOpts().Inputs; |
| 95 | + if (isec.size()) { |
0 commit comments