@@ -520,38 +520,44 @@ bool CompilerInstance::setup(const CompilerInvocation &Invoke,
520
520
}
521
521
522
522
bool CompilerInstance::setUpVirtualFileSystemOverlays () {
523
- if (Invocation.getFrontendOptions ().EnableCaching &&
524
- (!Invocation.getFrontendOptions ().CASFSRootIDs .empty () ||
525
- !Invocation.getFrontendOptions ().ClangIncludeTrees .empty ())) {
526
- // Set up CASFS as BaseFS.
523
+ if (Invocation.getFrontendOptions ().EnableCaching ) {
527
524
const auto &Opts = getInvocation ().getFrontendOptions ();
528
- auto FS =
529
- createCASFileSystem (*CAS, Opts.CASFSRootIDs , Opts.ClangIncludeTrees );
530
- if (!FS) {
531
- Diagnostics.diagnose (SourceLoc (), diag::error_cas,
532
- toString (FS.takeError ()));
533
- return true ;
525
+ if (!Invocation.getFrontendOptions ().CASFSRootIDs .empty () ||
526
+ !Invocation.getFrontendOptions ().ClangIncludeTrees .empty ()) {
527
+ // Set up CASFS as BaseFS.
528
+ auto FS =
529
+ createCASFileSystem (*CAS, Opts.CASFSRootIDs , Opts.ClangIncludeTrees );
530
+ if (!FS) {
531
+ Diagnostics.diagnose (SourceLoc (), diag::error_cas,
532
+ toString (FS.takeError ()));
533
+ return true ;
534
+ }
535
+ SourceMgr.setFileSystem (std::move (*FS));
536
+ }
537
+
538
+ // If we need to load any files from CAS, try load it now and overlay it.
539
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> MemFS =
540
+ new llvm::vfs::InMemoryFileSystem ();
541
+ const auto &ClangOpts = getInvocation ().getClangImporterOptions ();
542
+
543
+ if (!ClangOpts.BridgingHeaderPCHCacheKey .empty ()) {
544
+ if (auto loadedBuffer = loadCachedCompileResultFromCacheKey (
545
+ getObjectStore (), getActionCache (), Diagnostics,
546
+ ClangOpts.BridgingHeaderPCHCacheKey , ClangOpts.BridgingHeader ))
547
+ MemFS->addFile (Invocation.getClangImporterOptions ().BridgingHeader , 0 ,
548
+ std::move (loadedBuffer));
534
549
}
535
- SourceMgr.setFileSystem (std::move (*FS));
536
- }
537
-
538
- // If we have a bridging header cache key, try load it now and overlay it.
539
- if (!Invocation.getClangImporterOptions ().BridgingHeaderPCHCacheKey .empty () &&
540
- Invocation.getFrontendOptions ().EnableCaching ) {
541
- auto loadedBridgingBuffer = loadCachedCompileResultFromCacheKey (
542
- getObjectStore (), getActionCache (), Diagnostics,
543
- Invocation.getClangImporterOptions ().BridgingHeaderPCHCacheKey ,
544
- Invocation.getClangImporterOptions ().BridgingHeader );
545
- if (loadedBridgingBuffer) {
546
- llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> PCHFS =
547
- new llvm::vfs::InMemoryFileSystem ();
548
- PCHFS->addFile (Invocation.getClangImporterOptions ().BridgingHeader , 0 ,
549
- std::move (loadedBridgingBuffer));
550
- llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayVFS =
551
- new llvm::vfs::OverlayFileSystem (SourceMgr.getFileSystem ());
552
- OverlayVFS->pushOverlay (PCHFS);
553
- SourceMgr.setFileSystem (std::move (OverlayVFS));
550
+ if (!Opts.InputFileKey .empty ()) {
551
+ auto InputPath = Opts.InputsAndOutputs .getFilenameOfFirstInput ();
552
+ if (auto loadedBuffer = loadCachedCompileResultFromCacheKey (
553
+ getObjectStore (), getActionCache (), Diagnostics,
554
+ Opts.InputFileKey , InputPath))
555
+ MemFS->addFile (InputPath, 0 , std::move (loadedBuffer));
554
556
}
557
+ llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayVFS =
558
+ new llvm::vfs::OverlayFileSystem (SourceMgr.getFileSystem ());
559
+ OverlayVFS->pushOverlay (MemFS);
560
+ SourceMgr.setFileSystem (std::move (OverlayVFS));
555
561
}
556
562
557
563
auto ExpectedOverlay =
0 commit comments