@@ -831,11 +831,10 @@ 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;
836- AST->SourceMgr = new SourceManager (AST->getDiagnostics (),
837- AST->getFileManager (),
838- UserFilesAreVolatile);
836+ AST->SourceMgr = llvm::makeIntrusiveRefCnt<SourceManager>(
837+ AST->getDiagnostics (), AST->getFileManager (), UserFilesAreVolatile);
839838 AST->ModCache = createCrossProcessModuleCache ();
840839 AST->HSOpts = std::make_unique<HeaderSearchOptions>(HSOpts);
841840 AST->HSOpts ->ModuleFormat = std::string (PCHContainerRdr.getFormats ().front ());
@@ -858,20 +857,20 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
858857 Preprocessor &PP = *AST->PP ;
859858
860859 if (ToLoad >= LoadASTOnly)
861- AST->Ctx = new ASTContext (*AST-> LangOpts , AST-> getSourceManager (),
862- PP. getIdentifierTable (), PP.getSelectorTable (),
863- PP.getBuiltinInfo (),
864- AST->getTranslationUnitKind ());
860+ AST->Ctx = llvm::makeIntrusiveRefCnt< ASTContext>(
861+ *AST-> LangOpts , AST-> getSourceManager (), PP.getIdentifierTable (),
862+ PP. getSelectorTable (), PP.getBuiltinInfo (),
863+ AST->getTranslationUnitKind ());
865864
866865 DisableValidationForModuleKind disableValid =
867866 DisableValidationForModuleKind::None;
868867 if (::getenv (" LIBCLANG_DISABLE_PCH_VALIDATION" ))
869868 disableValid = DisableValidationForModuleKind::All;
870- AST->Reader = new ASTReader (PP, *AST-> ModCache , AST-> Ctx . get (),
871- PCHContainerRdr, *AST->CodeGenOpts , {} ,
872- /* isysroot= */ " " ,
873- /* DisableValidationKind =*/ disableValid ,
874- AllowASTWithCompilerErrors);
869+ AST->Reader = llvm::makeIntrusiveRefCnt< ASTReader>(
870+ PP, *AST-> ModCache , AST-> Ctx . get (), PCHContainerRdr, *AST->CodeGenOpts ,
871+ ArrayRef<std::shared_ptr<ModuleFileExtension>>() ,
872+ /* isysroot =*/ " " ,
873+ /* DisableValidationKind= */ disableValid, AllowASTWithCompilerErrors);
875874
876875 unsigned Counter = 0 ;
877876 AST->Reader ->setListener (std::make_unique<ASTInfoCollector>(
@@ -1191,9 +1190,11 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
11911190 // changed above in AddImplicitPreamble. If VFS is nullptr, rely on
11921191 // createFileManager to create one.
11931192 if (VFS && FileMgr && &FileMgr->getVirtualFileSystem () == VFS)
1194- Clang->setFileManager (&*FileMgr);
1195- else
1196- FileMgr = Clang->createFileManager (std::move (VFS));
1193+ Clang->setFileManager (FileMgr);
1194+ else {
1195+ Clang->createFileManager (std::move (VFS));
1196+ FileMgr = Clang->getFileManagerPtr ();
1197+ }
11971198
11981199 // Recover resources if we crash before exiting this method.
11991200 llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
@@ -1226,15 +1227,15 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
12261227
12271228 ResetForParse ();
12281229
1229- SourceMgr = new SourceManager ( getDiagnostics (), *FileMgr,
1230- UserFilesAreVolatile);
1230+ SourceMgr = llvm::makeIntrusiveRefCnt< SourceManager>(
1231+ getDiagnostics (), *FileMgr, + UserFilesAreVolatile);
12311232 if (!OverrideMainBuffer) {
12321233 checkAndRemoveNonDriverDiags (StoredDiagnostics);
12331234 TopLevelDeclsInPreamble.clear ();
12341235 }
12351236
12361237 // Create the source manager.
1237- Clang->setSourceManager (& getSourceManager ());
1238+ Clang->setSourceManager (getSourceManagerPtr ());
12381239
12391240 // If the main file has been overridden due to the use of a preamble,
12401241 // make that override happen and introduce the preamble.
@@ -1499,13 +1500,13 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
14991500 TheSema = CI.takeSema ();
15001501 Consumer = CI.takeASTConsumer ();
15011502 if (CI.hasASTContext ())
1502- Ctx = & CI.getASTContext ();
1503+ Ctx = CI.getASTContextPtr ();
15031504 if (CI.hasPreprocessor ())
15041505 PP = CI.getPreprocessorPtr ();
15051506 CI.setSourceManager (nullptr );
15061507 CI.setFileManager (nullptr );
15071508 if (CI.hasTarget ())
1508- Target = & CI.getTarget ();
1509+ Target = CI.getTargetPtr ();
15091510 Reader = CI.getASTReader ();
15101511 HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure ();
15111512 if (Invocation != CI.getInvocationPtr ()) {
@@ -1555,10 +1556,11 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
15551556 AST->Diagnostics = Diags;
15561557 AST->FileSystemOpts = CI->getFileSystemOpts ();
15571558 AST->Invocation = std::move (CI);
1558- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1559+ AST->FileMgr =
1560+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
15591561 AST->UserFilesAreVolatile = UserFilesAreVolatile;
1560- AST->SourceMgr = new SourceManager (AST-> getDiagnostics (), *AST-> FileMgr ,
1561- UserFilesAreVolatile);
1562+ AST->SourceMgr = llvm::makeIntrusiveRefCnt< SourceManager>(
1563+ AST-> getDiagnostics (), *AST-> FileMgr , UserFilesAreVolatile);
15621564 AST->ModCache = createCrossProcessModuleCache ();
15631565
15641566 return AST;
@@ -1646,10 +1648,10 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
16461648 AST->Reader = nullptr ;
16471649
16481650 // Create a file manager object to provide access to and cache the filesystem.
1649- Clang->setFileManager (& AST->getFileManager ());
1651+ Clang->setFileManager (AST->getFileManagerPtr ());
16501652
16511653 // Create the source manager.
1652- Clang->setSourceManager (& AST->getSourceManager ());
1654+ Clang->setSourceManager (AST->getSourceManagerPtr ());
16531655
16541656 FrontendAction *Act = Action;
16551657
@@ -1743,8 +1745,9 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
17431745 std::shared_ptr<CompilerInvocation> CI,
17441746 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
17451747 std::shared_ptr<DiagnosticOptions> DiagOpts,
1746- IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
1747- bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
1748+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
1749+ IntrusiveRefCntPtr<FileManager> FileMgr, bool OnlyLocalDecls,
1750+ CaptureDiagsKind CaptureDiagnostics,
17481751 unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
17491752 bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
17501753 bool UserFilesAreVolatile) {
@@ -1849,7 +1852,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCommandLine(
18491852 AST->FileSystemOpts = CI->getFileSystemOpts ();
18501853 AST->CodeGenOpts = std::make_unique<CodeGenOptions>(CI->getCodeGenOpts ());
18511854 VFS = createVFSFromCompilerInvocation (*CI, *Diags, VFS);
1852- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1855+ AST->FileMgr =
1856+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
18531857 AST->StorePreamblesInMemory = StorePreamblesInMemory;
18541858 AST->PreambleStoragePath = PreambleStoragePath;
18551859 AST->ModCache = createCrossProcessModuleCache ();
@@ -2210,7 +2214,8 @@ void ASTUnit::CodeComplete(
22102214 CodeCompleteConsumer &Consumer,
22112215 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
22122216 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diag, LangOptions &LangOpts,
2213- SourceManager &SourceMgr, FileManager &FileMgr,
2217+ llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr,
2218+ llvm::IntrusiveRefCntPtr<FileManager> FileMgr,
22142219 SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
22152220 SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers,
22162221 std::unique_ptr<SyntaxOnlyAction> Act) {
@@ -2265,7 +2270,7 @@ void ASTUnit::CodeComplete(
22652270 Clang->getDiagnostics (),
22662271 &StoredDiagnostics, nullptr );
22672272 ProcessWarningOptions (*Diag, Inv.getDiagnosticOpts (),
2268- FileMgr. getVirtualFileSystem ());
2273+ FileMgr-> getVirtualFileSystem ());
22692274
22702275 // Create the target instance.
22712276 if (!Clang->createTarget ()) {
@@ -2282,8 +2287,8 @@ void ASTUnit::CodeComplete(
22822287 " IR inputs not support here!" );
22832288
22842289 // Use the source and file managers that we were given.
2285- Clang->setFileManager (& FileMgr);
2286- Clang->setSourceManager (& SourceMgr);
2290+ Clang->setFileManager (FileMgr);
2291+ Clang->setSourceManager (SourceMgr);
22872292
22882293 // Remap files.
22892294 PreprocessorOpts.clearRemappedFiles ();
@@ -2301,7 +2306,7 @@ void ASTUnit::CodeComplete(
23012306
23022307 auto getUniqueID =
23032308 [&FileMgr](StringRef Filename) -> std::optional<llvm::sys::fs::UniqueID> {
2304- if (auto Status = FileMgr. getVirtualFileSystem ().status (Filename))
2309+ if (auto Status = FileMgr-> getVirtualFileSystem ().status (Filename))
23052310 return Status->getUniqueID ();
23062311 return std::nullopt ;
23072312 };
@@ -2322,7 +2327,7 @@ void ASTUnit::CodeComplete(
23222327 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
23232328 if (Preamble && Line > 1 && hasSameUniqueID (File, OriginalSourceFile)) {
23242329 OverrideMainBuffer = getMainBufferWithPrecompiledPreamble (
2325- PCHContainerOps, Inv, FileMgr. getVirtualFileSystemPtr (), false ,
2330+ PCHContainerOps, Inv, FileMgr-> getVirtualFileSystemPtr (), false ,
23262331 Line - 1 );
23272332 }
23282333
@@ -2333,7 +2338,7 @@ void ASTUnit::CodeComplete(
23332338 " No preamble was built, but OverrideMainBuffer is not null" );
23342339
23352340 IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
2336- FileMgr. getVirtualFileSystemPtr ();
2341+ FileMgr-> getVirtualFileSystemPtr ();
23372342 Preamble->AddImplicitPreamble (Clang->getInvocation (), VFS,
23382343 OverrideMainBuffer.get ());
23392344 // FIXME: there is no way to update VFS if it was changed by
0 commit comments