@@ -831,7 +831,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
831831 AST->CaptureDiagnostics = CaptureDiagnostics;
832832 AST->DiagOpts = DiagOpts;
833833 AST->Diagnostics = Diags;
834- AST->FileMgr = new FileManager (FileSystemOpts, VFS);
834+ AST->FileMgr = llvm::makeIntrusiveRefCnt< FileManager> (FileSystemOpts, VFS);
835835 AST->UserFilesAreVolatile = UserFilesAreVolatile;
836836 AST->SourceMgr = llvm::makeIntrusiveRefCnt<SourceManager>(
837837 AST->getDiagnostics (), AST->getFileManager (), UserFilesAreVolatile);
@@ -1190,9 +1190,11 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
11901190 // changed above in AddImplicitPreamble. If VFS is nullptr, rely on
11911191 // createFileManager to create one.
11921192 if (VFS && FileMgr && &FileMgr->getVirtualFileSystem () == VFS)
1193- Clang->setFileManager (&*FileMgr);
1194- else
1195- FileMgr = Clang->createFileManager (std::move (VFS));
1193+ Clang->setFileManager (FileMgr);
1194+ else {
1195+ Clang->createFileManager (std::move (VFS));
1196+ FileMgr = Clang->getFileManagerPtr ();
1197+ }
11961198
11971199 // Recover resources if we crash before exiting this method.
11981200 llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
@@ -1554,7 +1556,8 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
15541556 AST->Diagnostics = Diags;
15551557 AST->FileSystemOpts = CI->getFileSystemOpts ();
15561558 AST->Invocation = std::move (CI);
1557- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1559+ AST->FileMgr =
1560+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
15581561 AST->UserFilesAreVolatile = UserFilesAreVolatile;
15591562 AST->SourceMgr = llvm::makeIntrusiveRefCnt<SourceManager>(
15601563 AST->getDiagnostics (), *AST->FileMgr , UserFilesAreVolatile);
@@ -1645,7 +1648,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
16451648 AST->Reader = nullptr ;
16461649
16471650 // Create a file manager object to provide access to and cache the filesystem.
1648- Clang->setFileManager (& AST->getFileManager ());
1651+ Clang->setFileManager (AST->getFileManagerPtr ());
16491652
16501653 // Create the source manager.
16511654 Clang->setSourceManager (AST->getSourceManagerPtr ());
@@ -1742,8 +1745,9 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
17421745 std::shared_ptr<CompilerInvocation> CI,
17431746 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
17441747 std::shared_ptr<DiagnosticOptions> DiagOpts,
1745- IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
1746- bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
1748+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
1749+ IntrusiveRefCntPtr<FileManager> FileMgr, bool OnlyLocalDecls,
1750+ CaptureDiagsKind CaptureDiagnostics,
17471751 unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
17481752 bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
17491753 bool UserFilesAreVolatile) {
@@ -1848,7 +1852,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCommandLine(
18481852 AST->FileSystemOpts = CI->getFileSystemOpts ();
18491853 AST->CodeGenOpts = std::make_unique<CodeGenOptions>(CI->getCodeGenOpts ());
18501854 VFS = createVFSFromCompilerInvocation (*CI, *Diags, VFS);
1851- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1855+ AST->FileMgr =
1856+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
18521857 AST->StorePreamblesInMemory = StorePreamblesInMemory;
18531858 AST->PreambleStoragePath = PreambleStoragePath;
18541859 AST->ModCache = createCrossProcessModuleCache ();
@@ -2209,7 +2214,8 @@ void ASTUnit::CodeComplete(
22092214 CodeCompleteConsumer &Consumer,
22102215 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
22112216 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diag, LangOptions &LangOpts,
2212- llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr, FileManager &FileMgr,
2217+ llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr,
2218+ llvm::IntrusiveRefCntPtr<FileManager> FileMgr,
22132219 SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
22142220 SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers,
22152221 std::unique_ptr<SyntaxOnlyAction> Act) {
@@ -2264,7 +2270,7 @@ void ASTUnit::CodeComplete(
22642270 Clang->getDiagnostics (),
22652271 &StoredDiagnostics, nullptr );
22662272 ProcessWarningOptions (*Diag, Inv.getDiagnosticOpts (),
2267- FileMgr. getVirtualFileSystem ());
2273+ FileMgr-> getVirtualFileSystem ());
22682274
22692275 // Create the target instance.
22702276 if (!Clang->createTarget ()) {
@@ -2281,7 +2287,7 @@ void ASTUnit::CodeComplete(
22812287 " IR inputs not support here!" );
22822288
22832289 // Use the source and file managers that we were given.
2284- Clang->setFileManager (& FileMgr);
2290+ Clang->setFileManager (FileMgr);
22852291 Clang->setSourceManager (SourceMgr);
22862292
22872293 // Remap files.
@@ -2300,7 +2306,7 @@ void ASTUnit::CodeComplete(
23002306
23012307 auto getUniqueID =
23022308 [&FileMgr](StringRef Filename) -> std::optional<llvm::sys::fs::UniqueID> {
2303- if (auto Status = FileMgr. getVirtualFileSystem ().status (Filename))
2309+ if (auto Status = FileMgr-> getVirtualFileSystem ().status (Filename))
23042310 return Status->getUniqueID ();
23052311 return std::nullopt ;
23062312 };
@@ -2321,7 +2327,7 @@ void ASTUnit::CodeComplete(
23212327 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
23222328 if (Preamble && Line > 1 && hasSameUniqueID (File, OriginalSourceFile)) {
23232329 OverrideMainBuffer = getMainBufferWithPrecompiledPreamble (
2324- PCHContainerOps, Inv, FileMgr. getVirtualFileSystemPtr (), false ,
2330+ PCHContainerOps, Inv, FileMgr-> getVirtualFileSystemPtr (), false ,
23252331 Line - 1 );
23262332 }
23272333
@@ -2332,7 +2338,7 @@ void ASTUnit::CodeComplete(
23322338 " No preamble was built, but OverrideMainBuffer is not null" );
23332339
23342340 IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
2335- FileMgr. getVirtualFileSystemPtr ();
2341+ FileMgr-> getVirtualFileSystemPtr ();
23362342 Preamble->AddImplicitPreamble (Clang->getInvocation (), VFS,
23372343 OverrideMainBuffer.get ());
23382344 // FIXME: there is no way to update VFS if it was changed by
0 commit comments