-
Notifications
You must be signed in to change notification settings - Fork 15k
[clang] Avoid reparsing VFS overlay files for module dep collector #158372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) ChangesThis PR uses the new-ish Full diff: https://github.com/llvm/llvm-project/pull/158372.diff 4 Files Affected:
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 31a8d75fec4bd..3e67cf157cb1c 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);
diff --git a/clang/test/VFS/broken-vfs-module-dep.c b/clang/test/VFS/broken-vfs-module-dep.c
index 2336306de8c6d..1c371a13e85c9 100644
--- a/clang/test/VFS/broken-vfs-module-dep.c
+++ b/clang/test/VFS/broken-vfs-module-dep.c
@@ -2,6 +2,5 @@
// RUN: mkdir -p %t
// RUN: not %clang_cc1 -module-dependency-dir %t -ivfsoverlay %S/Inputs/invalid-yaml.yaml %s 2>&1 | FileCheck %s
-// CHECK: error: Unexpected token
// CHECK: error: Unexpected token
// CHECK: 1 error generated
diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h
index d97677305a39f..8007f3c853f20 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -1114,14 +1114,10 @@ class LLVM_ABI RedirectingFileSystem
};
/// Collect all pairs of <virtual path, real path> entries from the
-/// \p YAMLFilePath. This is used by the module dependency collector to forward
+/// \p VFS. This is used by the module dependency collector to forward
/// the entries into the reproducer output VFS YAML file.
-LLVM_ABI void collectVFSFromYAML(
- std::unique_ptr<llvm::MemoryBuffer> Buffer,
- llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath,
- SmallVectorImpl<YAMLVFSEntry> &CollectedEntries,
- void *DiagContext = nullptr,
- IntrusiveRefCntPtr<FileSystem> ExternalFS = getRealFileSystem());
+void collectVFSEntries(RedirectingFileSystem &VFS,
+ SmallVectorImpl<YAMLVFSEntry> &CollectedEntries);
class YAMLVFSWriter {
std::vector<YAMLVFSEntry> Mappings;
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index 5d4248819f1fb..cf784595c2f1c 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -2707,19 +2707,9 @@ static void getVFSEntries(RedirectingFileSystem::Entry *SrcE,
Entries.push_back(YAMLVFSEntry(VPath.c_str(), FE->getExternalContentsPath()));
}
-void vfs::collectVFSFromYAML(std::unique_ptr<MemoryBuffer> Buffer,
- SourceMgr::DiagHandlerTy DiagHandler,
- StringRef YAMLFilePath,
- SmallVectorImpl<YAMLVFSEntry> &CollectedEntries,
- void *DiagContext,
- IntrusiveRefCntPtr<FileSystem> ExternalFS) {
- std::unique_ptr<RedirectingFileSystem> VFS = RedirectingFileSystem::create(
- std::move(Buffer), DiagHandler, YAMLFilePath, DiagContext,
- std::move(ExternalFS));
- if (!VFS)
- return;
- ErrorOr<RedirectingFileSystem::LookupResult> RootResult =
- VFS->lookupPath("/");
+void vfs::collectVFSEntries(RedirectingFileSystem &VFS,
+ SmallVectorImpl<YAMLVFSEntry> &CollectedEntries) {
+ ErrorOr<RedirectingFileSystem::LookupResult> RootResult = VFS.lookupPath("/");
if (!RootResult)
return;
SmallVector<StringRef, 8> Components;
|
This PR uses the new-ish
llvm::vfs::FileSystem::visit()
interface to collect VFS overlay entries from an existingFileSystem
instance rather than parsing the VFS YAML file anew. This prevents duplicate diagnostics as observed byclang/test/VFS/broken-vfs-module-dep.c
.