Skip to content

Conversation

@naveen-seth
Copy link
Contributor

This patch is part of a series of splitting the work from #169964 into smaller changes (see review linked below).

As part of this work, the regular and by-name dependency scanning APIs need to be extended to allow the VFS to be initialized via the initVFS- helpers before invoking the scanning API, with the resulting overlay filesystem passed into the worker instead.

To make the newly added API changes consistent, this patch updates both helpers to return an OverlayFileSystem.

#169964 (review)

…leSystem (NFC)

This patch is part of a series of splitting the work from llvm#169964 into
smaller changes (see comment linked below).

The PR extends the regular and by-name dependency scanning APIs to
allow the VFS to be initialized via the initVFS helpers before
invoking the scanning APIs, with the resulting overlay filesystem
passed into the worker.

To make the API consistent, this patch updates both helpers to return
an OverlayFileSystem.

llvm#169964 (review)
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Dec 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 13, 2025

@llvm/pr-subscribers-clang

Author: Naveen Seth Hanig (naveen-seth)

Changes

This patch is part of a series of splitting the work from #169964 into smaller changes (see review linked below).

As part of this work, the regular and by-name dependency scanning APIs need to be extended to allow the VFS to be initialized via the initVFS- helpers before invoking the scanning API, with the resulting overlay filesystem passed into the worker instead.

To make the newly added API changes consistent, this patch updates both helpers to return an OverlayFileSystem.

#169964 (review)


Full diff: https://github.com/llvm/llvm-project/pull/172166.diff

2 Files Affected:

  • (modified) clang/include/clang/DependencyScanning/DependencyScannerImpl.h (+2-1)
  • (modified) clang/lib/DependencyScanning/DependencyScannerImpl.cpp (+3-4)
diff --git a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
index 9e23c0f87f273..f43c7f70183fd 100644
--- a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
+++ b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
@@ -98,7 +98,8 @@ std::unique_ptr<CompilerInvocation>
 createCompilerInvocation(ArrayRef<std::string> CommandLine,
                          DiagnosticsEngine &Diags);
 
-std::pair<IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::string>>
+std::pair<IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>,
+          std::vector<std::string>>
 initVFSForTUBufferScanning(IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
                            ArrayRef<std::string> CommandLine,
                            StringRef WorkingDirectory,
diff --git a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
index 191ffabeea4f2..201230d7d6a8e 100644
--- a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
+++ b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
@@ -430,7 +430,8 @@ dependencies::createCompilerInvocation(ArrayRef<std::string> CommandLine,
   return Invocation;
 }
 
-std::pair<IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::string>>
+std::pair<IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>,
+          std::vector<std::string>>
 dependencies::initVFSForTUBufferScanning(
     IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
     ArrayRef<std::string> CommandLine, StringRef WorkingDirectory,
@@ -438,7 +439,6 @@ dependencies::initVFSForTUBufferScanning(
   // Reset what might have been modified in the previous worker invocation.
   BaseFS->setCurrentWorkingDirectory(WorkingDirectory);
 
-  IntrusiveRefCntPtr<llvm::vfs::FileSystem> ModifiedFS;
   auto OverlayFS =
       llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(BaseFS);
   auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
@@ -449,11 +449,10 @@ dependencies::initVFSForTUBufferScanning(
   IntrusiveRefCntPtr<llvm::vfs::FileSystem> InMemoryOverlay = InMemoryFS;
 
   OverlayFS->pushOverlay(InMemoryOverlay);
-  ModifiedFS = OverlayFS;
   std::vector<std::string> ModifiedCommandLine(CommandLine);
   ModifiedCommandLine.emplace_back(InputPath);
 
-  return std::make_pair(ModifiedFS, ModifiedCommandLine);
+  return std::make_pair(OverlayFS, ModifiedCommandLine);
 }
 
 std::pair<IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>,

@naveen-seth
Copy link
Contributor Author

For additional context, the newly added calls in #169964 all accept an OverlayFileSystem:

bool DependencyScanningWorker::initializeCompilerInstanceWithContext(
StringRef CWD, ArrayRef<std::string> CommandLine,
std::unique_ptr<DiagnosticsEngineWithDiagOpts> DiagEngineWithDiagOpts,
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS) {

Because I want the upcoming additions to computeDependencies to be consistent with this and also accept an OverlayFileSystem, this aligns the return types of the helpers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants