diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index f21f5c29db3a1..ad1c2cfdb2430 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -1040,7 +1040,7 @@ class CompilerInstance : public ModuleLoader { std::pair, std::shared_ptr> - createCASDatabases(); + getOrCreateCASDatabases(); }; } // end namespace clang diff --git a/clang/lib/Frontend/CompileJobCache.cpp b/clang/lib/Frontend/CompileJobCache.cpp index f5f45b47f2d0c..84e3ab22bc5b8 100644 --- a/clang/lib/Frontend/CompileJobCache.cpp +++ b/clang/lib/Frontend/CompileJobCache.cpp @@ -296,7 +296,7 @@ std::optional CompileJobCache::initialize(CompilerInstance &Clang) { if (!CacheCompileJob) return std::nullopt; - std::tie(CAS, Cache) = Clang.createCASDatabases(); + std::tie(CAS, Cache) = Clang.getOrCreateCASDatabases(); if (!CAS || !Cache) return 1; // Exit with error! diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 238303ed963c3..cf8a970067144 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -296,6 +296,10 @@ void CompilerInstance::createVirtualFileSystem( DiagnosticsEngine Diags(DiagnosticIDs::create(), DiagOpts, DC, /*ShouldOwnClient=*/false); + std::tie(CAS, ActionCache) = + getInvocation().getCASOpts().getOrCreateDatabases( + Diags, /*CreateEmptyCASOnFailure=*/false); + VFS = createVFSFromCompilerInvocation(getInvocation(), Diags, std::move(BaseFS), CAS); // FIXME: Should this go into createVFSFromCompilerInvocation? @@ -970,7 +974,7 @@ llvm::vfs::OutputBackend &CompilerInstance::getOrCreateOutputManager() { std::pair, std::shared_ptr> -CompilerInstance::createCASDatabases() { +CompilerInstance::getOrCreateCASDatabases() { // Create a new CAS databases from the CompilerInvocation. Future calls to // createFileManager() will use the same CAS. std::tie(CAS, ActionCache) = @@ -982,13 +986,13 @@ CompilerInstance::createCASDatabases() { llvm::cas::ObjectStore &CompilerInstance::getOrCreateObjectStore() { if (!CAS) - createCASDatabases(); + getOrCreateCASDatabases(); return *CAS; } llvm::cas::ActionCache &CompilerInstance::getOrCreateActionCache() { if (!ActionCache) - createCASDatabases(); + getOrCreateCASDatabases(); return *ActionCache; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 5c11a86711d79..fff5458f78847 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1536,9 +1536,6 @@ createBaseFS(const FileSystemOptions &FSOpts, const FrontendOptions &FEOpts, const CASOptions &CASOpts, DiagnosticsEngine &Diags, IntrusiveRefCntPtr BaseFS, std::shared_ptr OverrideCAS) { - if (!OverrideCAS) - return BaseFS; - if (FSOpts.CASFileSystemRootID.empty() && FEOpts.CASIncludeTreeID.empty()) return BaseFS; diff --git a/clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp b/clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp index e27bd3e218017..c6900f9b84290 100644 --- a/clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp +++ b/clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp @@ -282,10 +282,11 @@ void dependencies::addReversePrefixMappingFileSystem( llvm::PrefixMapper ReverseMapper; ReverseMapper.addInverseRange(PrefixMapper.getMappings()); ReverseMapper.sort(); - std::unique_ptr FS = + IntrusiveRefCntPtr FS = llvm::vfs::createPrefixMappingFileSystem( std::move(ReverseMapper), &ScanInstance.getVirtualFileSystem()); + ScanInstance.setVirtualFileSystem(FS); ScanInstance.getFileManager().setVirtualFileSystem(std::move(FS)); } diff --git a/clang/test/CAS/output-path-error.c b/clang/test/CAS/output-path-error.c index b217ba48402cf..a221f3bb29bf0 100644 --- a/clang/test/CAS/output-path-error.c +++ b/clang/test/CAS/output-path-error.c @@ -19,4 +19,4 @@ // RUN: cat %t/output.txt | FileCheck %s --check-prefix=ERROR // CACHE-MISS: remark: compile job cache miss -// ERROR: fatal error: CAS missing expected root-id +// ERROR: fatal error: CAS filesystem cannot be initialized from root-id 'llvmcas://{{.*}}': cannot get reference to root FS