diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-09-15 09:37:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-15 09:37:19 -0700 |
commit | 4957c473bc73a3a0bf1037adec770547c4a0aa02 (patch) | |
tree | a1e40ddddc3559d7c6de6ed7b8bd295124d65567 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 985dc69a2def6812ba310c8fa431a0679f1b8163 (diff) | |
download | llvm-4957c473bc73a3a0bf1037adec770547c4a0aa02.zip llvm-4957c473bc73a3a0bf1037adec770547c4a0aa02.tar.gz llvm-4957c473bc73a3a0bf1037adec770547c4a0aa02.tar.bz2 |
[clang] Avoid reparsing VFS overlay files for module dep collector (#158372)
This PR uses the new-ish `llvm::vfs::FileSystem::visit()` interface to
collect VFS overlay entries from an existing `FileSystem` instance
rather than parsing the VFS YAML file anew. This prevents duplicate
diagnostics as observed by `clang/test/VFS/broken-vfs-module-dep.c`.
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 31a8d75..3e67cf1 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -271,19 +271,12 @@ static void collectIncludePCH(CompilerInstance &CI, static void collectVFSEntries(CompilerInstance &CI, std::shared_ptr<ModuleDependencyCollector> MDC) { - if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) - return; - // Collect all VFS found. SmallVector<llvm::vfs::YAMLVFSEntry, 16> VFSEntries; - for (const std::string &VFSFile : CI.getHeaderSearchOpts().VFSOverlayFiles) { - llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer = - llvm::MemoryBuffer::getFile(VFSFile); - if (!Buffer) - return; - llvm::vfs::collectVFSFromYAML(std::move(Buffer.get()), - /*DiagHandler*/ nullptr, VFSFile, VFSEntries); - } + CI.getVirtualFileSystem().visit([&](llvm::vfs::FileSystem &VFS) { + if (auto *RedirectingVFS = dyn_cast<llvm::vfs::RedirectingFileSystem>(&VFS)) + llvm::vfs::collectVFSEntries(*RedirectingVFS, VFSEntries); + }); for (auto &E : VFSEntries) MDC->addFile(E.VPath, E.RPath); |