Skip to content

Commit 59ca873

Browse files
committed
[clang] Fix CAS initialization after upstream llvm#158381
With the early initialization of the VFS, the CAS is now being initialized too late. This PR initializes CAS along with the VFS so that the CAS filesystem can sit at the bottom.
1 parent 814c3a7 commit 59ca873

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ class CompilerInstance : public ModuleLoader {
530530
/// Get the CAS, or create it using the configuration in CompilerInvocation.
531531
llvm::cas::ObjectStore &getOrCreateObjectStore();
532532
llvm::cas::ActionCache &getOrCreateActionCache();
533+
std::shared_ptr<llvm::cas::ObjectStore> getObjectStorePtr() const {
534+
return CAS;
535+
}
536+
std::shared_ptr<llvm::cas::ActionCache> getActionCachePtr() const {
537+
return ActionCache;
538+
}
533539

534540
/// @}
535541
/// @name Source Manager

clang/lib/Frontend/CompileJobCache.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ std::optional<int> CompileJobCache::initialize(CompilerInstance &Clang) {
296296
if (!CacheCompileJob)
297297
return std::nullopt;
298298

299-
std::tie(CAS, Cache) = Clang.createCASDatabases();
299+
CAS = Clang.getObjectStorePtr();
300+
Cache = Clang.getActionCachePtr();
300301
if (!CAS || !Cache)
301302
return 1; // Exit with error!
302303

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ void CompilerInstance::createVirtualFileSystem(
296296
DiagnosticsEngine Diags(DiagnosticIDs::create(), DiagOpts, DC,
297297
/*ShouldOwnClient=*/false);
298298

299+
std::tie(CAS, ActionCache) =
300+
getInvocation().getCASOpts().getOrCreateDatabases(
301+
Diags, /*CreateEmptyCASOnFailure=*/false);
302+
299303
VFS = createVFSFromCompilerInvocation(getInvocation(), Diags,
300304
std::move(BaseFS), CAS);
301305
// FIXME: Should this go into createVFSFromCompilerInvocation?

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,9 +1536,6 @@ createBaseFS(const FileSystemOptions &FSOpts, const FrontendOptions &FEOpts,
15361536
const CASOptions &CASOpts, DiagnosticsEngine &Diags,
15371537
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
15381538
std::shared_ptr<llvm::cas::ObjectStore> OverrideCAS) {
1539-
if (!OverrideCAS)
1540-
return BaseFS;
1541-
15421539
if (FSOpts.CASFileSystemRootID.empty() && FEOpts.CASIncludeTreeID.empty())
15431540
return BaseFS;
15441541

clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,11 @@ void dependencies::addReversePrefixMappingFileSystem(
282282
llvm::PrefixMapper ReverseMapper;
283283
ReverseMapper.addInverseRange(PrefixMapper.getMappings());
284284
ReverseMapper.sort();
285-
std::unique_ptr<llvm::vfs::FileSystem> FS =
285+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
286286
llvm::vfs::createPrefixMappingFileSystem(
287287
std::move(ReverseMapper), &ScanInstance.getVirtualFileSystem());
288288

289+
ScanInstance.setVirtualFileSystem(FS);
289290
ScanInstance.getFileManager().setVirtualFileSystem(std::move(FS));
290291
}
291292

clang/test/CAS/output-path-error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
// RUN: cat %t/output.txt | FileCheck %s --check-prefix=ERROR
2020

2121
// CACHE-MISS: remark: compile job cache miss
22-
// ERROR: fatal error: CAS missing expected root-id
22+
// ERROR: fatal error: CAS filesystem cannot be initialized from root-id 'llvmcas://{{.*}}': cannot get reference to root FS

0 commit comments

Comments
 (0)