Fix direct clang cc1 emit-pcm commands with vfs overlay on Windows (#85325)

Explicit module builds currently fail on Windows because
direct-clang-cc1-module-build emit-pcm commands take overlaid system
module map files as inputs but miss the clang VFS overlay. This change
adds the overlay and fixes explicit module builds on Windows.
This commit is contained in:
Hiroshi Yamauchi
2025-11-12 21:03:15 -08:00
committed by GitHub
parent 2db0e8aea8
commit a96b57de17
6 changed files with 87 additions and 16 deletions

View File

@@ -711,6 +711,25 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() {
new llvm::vfs::OverlayFileSystem(MemFS);
OverlayVFS->pushOverlay(SourceMgr.getFileSystem());
SourceMgr.setFileSystem(std::move(OverlayVFS));
} else {
// For non-caching -direct-clang-cc1-module-build emit-pcm build,
// setup the clang VFS so it can find system modulemap files
// (like vcruntime.modulemap) as an input file.
if (Invocation.getClangImporterOptions().DirectClangCC1ModuleBuild &&
Invocation.getFrontendOptions().RequestedAction ==
FrontendOptions::ActionType::EmitPCM) {
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
SourceMgr.getFileSystem();
ClangInvocationFileMappingContext Context(
Invocation.getLangOptions(), Invocation.getSearchPathOptions(),
Invocation.getClangImporterOptions(), Invocation.getCASOptions(),
Diagnostics);
ClangInvocationFileMapping FileMapping = applyClangInvocationMapping(
Context, nullptr, VFS, /*suppressDiagnostic=*/false);
if (!FileMapping.redirectedFiles.empty()) {
SourceMgr.setFileSystem(std::move(VFS));
}
}
}
auto ExpectedOverlay =