Skip to content

Commit 46825e9

Browse files
committed
Merge pull request #11450 from swiftlang/jan_svoboda/cas-fix-early-vfs
[clang] Fix CAS initialization after upstream llvm#158381 (cherry picked from commit 6d73002)
1 parent b041249 commit 46825e9

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
@@ -1030,7 +1030,7 @@ class CompilerInstance : public ModuleLoader {
10301030

10311031
std::pair<std::shared_ptr<llvm::cas::ObjectStore>,
10321032
std::shared_ptr<llvm::cas::ActionCache>>
1033-
createCASDatabases();
1033+
getOrCreateCASDatabases();
10341034
};
10351035

10361036
} // 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
@@ -293,6 +293,10 @@ void CompilerInstance::createVirtualFileSystem(
293293
DiagnosticsEngine Diags(new DiagnosticIDs, DiagOpts, DC,
294294
/*ShouldOwnClient=*/false);
295295

296+
std::tie(CAS, ActionCache) =
297+
getInvocation().getCASOpts().getOrCreateDatabases(
298+
Diags, /*CreateEmptyCASOnFailure=*/false);
299+
296300
VFS = createVFSFromCompilerInvocation(getInvocation(), Diags,
297301
std::move(BaseFS), CAS);
298302
// FIXME: Should this go into createVFSFromCompilerInvocation?
@@ -964,7 +968,7 @@ llvm::vfs::OutputBackend &CompilerInstance::getOrCreateOutputBackend() {
964968

965969
std::pair<std::shared_ptr<llvm::cas::ObjectStore>,
966970
std::shared_ptr<llvm::cas::ActionCache>>
967-
CompilerInstance::createCASDatabases() {
971+
CompilerInstance::getOrCreateCASDatabases() {
968972
// Create a new CAS databases from the CompilerInvocation. Future calls to
969973
// createFileManager() will use the same CAS.
970974
std::tie(CAS, ActionCache) =
@@ -976,13 +980,13 @@ CompilerInstance::createCASDatabases() {
976980

977981
llvm::cas::ObjectStore &CompilerInstance::getOrCreateObjectStore() {
978982
if (!CAS)
979-
createCASDatabases();
983+
getOrCreateCASDatabases();
980984
return *CAS;
981985
}
982986

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

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,6 @@ createBaseFS(const FileSystemOptions &FSOpts, const FrontendOptions &FEOpts,
15291529
const CASOptions &CASOpts, DiagnosticsEngine &Diags,
15301530
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
15311531
std::shared_ptr<llvm::cas::ObjectStore> OverrideCAS) {
1532-
if (!OverrideCAS)
1533-
return BaseFS;
1534-
15351532
if (FSOpts.CASFileSystemRootID.empty() && FEOpts.CASIncludeTreeID.empty())
15361533
return BaseFS;
15371534

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)