Skip to content

Commit 93b3165

Browse files
jansvoboda11qiongsiwu
authored andcommitted
Merge pull request llvm#11450 from swiftlang/jan_svoboda/cas-fix-early-vfs
[clang] Fix CAS initialization after upstream llvm#158381 (cherry picked from commit 6d73002)
1 parent af70946 commit 93b3165

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
@@ -303,6 +303,10 @@ void CompilerInstance::createVirtualFileSystem(
303303
DiagnosticsEngine Diags(DiagnosticIDs::create(), DiagOpts, DC,
304304
/*ShouldOwnClient=*/false);
305305

306+
std::tie(CAS, ActionCache) =
307+
getInvocation().getCASOpts().getOrCreateDatabases(
308+
Diags, /*CreateEmptyCASOnFailure=*/false);
309+
306310
VFS = createVFSFromCompilerInvocation(getInvocation(), Diags,
307311
std::move(BaseFS), CAS);
308312
// FIXME: Should this go into createVFSFromCompilerInvocation?
@@ -974,7 +978,7 @@ llvm::vfs::OutputBackend &CompilerInstance::getOrCreateOutputBackend() {
974978

975979
std::pair<std::shared_ptr<llvm::cas::ObjectStore>,
976980
std::shared_ptr<llvm::cas::ActionCache>>
977-
CompilerInstance::createCASDatabases() {
981+
CompilerInstance::getOrCreateCASDatabases() {
978982
// Create a new CAS databases from the CompilerInvocation. Future calls to
979983
// createFileManager() will use the same CAS.
980984
std::tie(CAS, ActionCache) =
@@ -986,13 +990,13 @@ CompilerInstance::createCASDatabases() {
986990

987991
llvm::cas::ObjectStore &CompilerInstance::getOrCreateObjectStore() {
988992
if (!CAS)
989-
createCASDatabases();
993+
getOrCreateCASDatabases();
990994
return *CAS;
991995
}
992996

993997
llvm::cas::ActionCache &CompilerInstance::getOrCreateActionCache() {
994998
if (!ActionCache)
995-
createCASDatabases();
999+
getOrCreateCASDatabases();
9961000
return *ActionCache;
9971001
}
9981002

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,9 +1538,6 @@ createBaseFS(const FileSystemOptions &FSOpts, const FrontendOptions &FEOpts,
15381538
const CASOptions &CASOpts, DiagnosticsEngine &Diags,
15391539
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
15401540
std::shared_ptr<llvm::cas::ObjectStore> OverrideCAS) {
1541-
if (!OverrideCAS)
1542-
return BaseFS;
1543-
15441541
if (FSOpts.CASFileSystemRootID.empty() && FEOpts.CASIncludeTreeID.empty())
15451542
return BaseFS;
15461543

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)