Skip to content

Commit 6d73002

Browse files
authored
Merge pull request #11450 from swiftlang/jan_svoboda/cas-fix-early-vfs
[clang] Fix CAS initialization after upstream llvm#158381
2 parents 9a59bc8 + 06cbfee commit 6d73002

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ class CompilerInstance : public ModuleLoader {
10401040

10411041
std::pair<std::shared_ptr<llvm::cas::ObjectStore>,
10421042
std::shared_ptr<llvm::cas::ActionCache>>
1043-
createCASDatabases();
1043+
getOrCreateCASDatabases();
10441044
};
10451045

10461046
} // end namespace clang

clang/lib/Frontend/CompileJobCache.cpp

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

299-
std::tie(CAS, Cache) = Clang.createCASDatabases();
299+
std::tie(CAS, Cache) = Clang.getOrCreateCASDatabases();
300300
if (!CAS || !Cache)
301301
return 1; // Exit with error!
302302

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 7 additions & 3 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?
@@ -970,7 +974,7 @@ llvm::vfs::OutputBackend &CompilerInstance::getOrCreateOutputManager() {
970974

971975
std::pair<std::shared_ptr<llvm::cas::ObjectStore>,
972976
std::shared_ptr<llvm::cas::ActionCache>>
973-
CompilerInstance::createCASDatabases() {
977+
CompilerInstance::getOrCreateCASDatabases() {
974978
// Create a new CAS databases from the CompilerInvocation. Future calls to
975979
// createFileManager() will use the same CAS.
976980
std::tie(CAS, ActionCache) =
@@ -982,13 +986,13 @@ CompilerInstance::createCASDatabases() {
982986

983987
llvm::cas::ObjectStore &CompilerInstance::getOrCreateObjectStore() {
984988
if (!CAS)
985-
createCASDatabases();
989+
getOrCreateCASDatabases();
986990
return *CAS;
987991
}
988992

989993
llvm::cas::ActionCache &CompilerInstance::getOrCreateActionCache() {
990994
if (!ActionCache)
991-
createCASDatabases();
995+
getOrCreateCASDatabases();
992996
return *ActionCache;
993997
}
994998

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)