@@ -580,12 +580,19 @@ bool CompilerInstance::setupForReplay(const CompilerInvocation &Invoke,
580580}
581581
582582bool CompilerInstance::setUpVirtualFileSystemOverlays () {
583+ const auto &CASOpts = getInvocation ().getCASOptions ();
584+ if (CASOpts.EnableCaching && !CASOpts.HasImmutableFileSystem &&
585+ FrontendOptions::supportCompilationCaching (
586+ Invocation.getFrontendOptions ().RequestedAction )) {
587+ Diagnostics.diagnose (SourceLoc (), diag::error_caching_no_cas_fs);
588+ return true ;
589+ }
590+
583591 if (Invocation.getCASOptions ().requireCASFS ()) {
584- const auto &Opts = getInvocation ().getCASOptions ();
585- if (!Opts.CASFSRootIDs .empty () || !Opts.ClangIncludeTrees .empty ()) {
592+ if (!CASOpts.CASFSRootIDs .empty () || !CASOpts.ClangIncludeTrees .empty ()) {
586593 // Set up CASFS as BaseFS.
587- auto FS =
588- createCASFileSystem (*CAS, Opts. CASFSRootIDs , Opts .ClangIncludeTrees );
594+ auto FS = createCASFileSystem (*CAS, CASOpts. CASFSRootIDs ,
595+ CASOpts .ClangIncludeTrees );
589596 if (!FS) {
590597 Diagnostics.diagnose (SourceLoc (), diag::error_cas,
591598 toString (FS.takeError ()));
@@ -599,10 +606,10 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() {
599606 new llvm::vfs::InMemoryFileSystem ();
600607 const auto &ClangOpts = getInvocation ().getClangImporterOptions ();
601608
602- if (!Opts .BridgingHeaderPCHCacheKey .empty ()) {
609+ if (!CASOpts .BridgingHeaderPCHCacheKey .empty ()) {
603610 if (auto loadedBuffer = loadCachedCompileResultFromCacheKey (
604611 getObjectStore (), getActionCache (), Diagnostics,
605- Opts .BridgingHeaderPCHCacheKey , file_types::ID::TY_PCH,
612+ CASOpts .BridgingHeaderPCHCacheKey , file_types::ID::TY_PCH,
606613 ClangOpts.BridgingHeader ))
607614 MemFS->addFile (Invocation.getClangImporterOptions ().BridgingHeader , 0 ,
608615 std::move (loadedBuffer));
@@ -611,7 +618,7 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() {
611618 SourceLoc (), diag::error_load_input_from_cas,
612619 Invocation.getClangImporterOptions ().BridgingHeader );
613620 }
614- if (!Opts .InputFileKey .empty ()) {
621+ if (!CASOpts .InputFileKey .empty ()) {
615622 if (Invocation.getFrontendOptions ()
616623 .InputsAndOutputs .getAllInputs ()
617624 .size () != 1 )
@@ -624,7 +631,7 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() {
624631 llvm::sys::path::filename (InputPath));
625632 if (auto loadedBuffer = loadCachedCompileResultFromCacheKey (
626633 getObjectStore (), getActionCache (), Diagnostics,
627- Opts .InputFileKey , Type, InputPath))
634+ CASOpts .InputFileKey , Type, InputPath))
628635 MemFS->addFile (InputPath, 0 , std::move (loadedBuffer));
629636 else
630637 Diagnostics.diagnose (SourceLoc (), diag::error_load_input_from_cas,
0 commit comments