@@ -822,11 +822,10 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
822822 AST->CaptureDiagnostics = CaptureDiagnostics;
823823 AST->DiagOpts = DiagOpts;
824824 AST->Diagnostics = Diags;
825- AST->FileMgr = new FileManager (FileSystemOpts, VFS);
825+ AST->FileMgr = llvm::makeIntrusiveRefCnt< FileManager> (FileSystemOpts, VFS);
826826 AST->UserFilesAreVolatile = UserFilesAreVolatile;
827- AST->SourceMgr = new SourceManager (AST->getDiagnostics (),
828- AST->getFileManager (),
829- UserFilesAreVolatile);
827+ AST->SourceMgr = llvm::makeIntrusiveRefCnt<SourceManager>(
828+ AST->getDiagnostics (), AST->getFileManager (), UserFilesAreVolatile);
830829 AST->ModCache = createCrossProcessModuleCache ();
831830 AST->HSOpts = std::make_unique<HeaderSearchOptions>(HSOpts);
832831 AST->HSOpts ->ModuleFormat = std::string (PCHContainerRdr.getFormats ().front ());
@@ -849,17 +848,19 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
849848 Preprocessor &PP = *AST->PP ;
850849
851850 if (ToLoad >= LoadASTOnly)
852- AST->Ctx = new ASTContext (*AST-> LangOpts , AST-> getSourceManager (),
853- PP. getIdentifierTable (), PP.getSelectorTable (),
854- PP.getBuiltinInfo (),
855- AST->getTranslationUnitKind ());
851+ AST->Ctx = llvm::makeIntrusiveRefCnt< ASTContext>(
852+ *AST-> LangOpts , AST-> getSourceManager (), PP.getIdentifierTable (),
853+ PP. getSelectorTable (), PP.getBuiltinInfo (),
854+ AST->getTranslationUnitKind ());
856855
857856 DisableValidationForModuleKind disableValid =
858857 DisableValidationForModuleKind::None;
859858 if (::getenv (" LIBCLANG_DISABLE_PCH_VALIDATION" ))
860859 disableValid = DisableValidationForModuleKind::All;
861- AST->Reader = new ASTReader (
862- PP, *AST->ModCache , AST->Ctx .get (), PCHContainerRdr, {}, /* isysroot=*/ " " ,
860+ AST->Reader = llvm::makeIntrusiveRefCnt<ASTReader>(
861+ PP, *AST->ModCache , AST->Ctx .get (), PCHContainerRdr,
862+ ArrayRef<std::shared_ptr<ModuleFileExtension>>(),
863+ /* isysroot=*/ " " ,
863864 /* DisableValidationKind=*/ disableValid, AllowASTWithCompilerErrors);
864865
865866 unsigned Counter = 0 ;
@@ -1180,9 +1181,11 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
11801181 // changed above in AddImplicitPreamble. If VFS is nullptr, rely on
11811182 // createFileManager to create one.
11821183 if (VFS && FileMgr && &FileMgr->getVirtualFileSystem () == VFS)
1183- Clang->setFileManager (&*FileMgr);
1184- else
1185- FileMgr = Clang->createFileManager (std::move (VFS));
1184+ Clang->setFileManager (FileMgr);
1185+ else {
1186+ Clang->createFileManager (std::move (VFS));
1187+ FileMgr = Clang->getFileManagerPtr ();
1188+ }
11861189
11871190 // Recover resources if we crash before exiting this method.
11881191 llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
@@ -1215,15 +1218,15 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
12151218
12161219 ResetForParse ();
12171220
1218- SourceMgr = new SourceManager ( getDiagnostics (), *FileMgr,
1219- UserFilesAreVolatile);
1221+ SourceMgr = llvm::makeIntrusiveRefCnt< SourceManager>(
1222+ getDiagnostics (), *FileMgr, + UserFilesAreVolatile);
12201223 if (!OverrideMainBuffer) {
12211224 checkAndRemoveNonDriverDiags (StoredDiagnostics);
12221225 TopLevelDeclsInPreamble.clear ();
12231226 }
12241227
12251228 // Create the source manager.
1226- Clang->setSourceManager (& getSourceManager ());
1229+ Clang->setSourceManager (getSourceManagerPtr ());
12271230
12281231 // If the main file has been overridden due to the use of a preamble,
12291232 // make that override happen and introduce the preamble.
@@ -1488,13 +1491,13 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
14881491 TheSema = CI.takeSema ();
14891492 Consumer = CI.takeASTConsumer ();
14901493 if (CI.hasASTContext ())
1491- Ctx = & CI.getASTContext ();
1494+ Ctx = CI.getASTContextPtr ();
14921495 if (CI.hasPreprocessor ())
14931496 PP = CI.getPreprocessorPtr ();
14941497 CI.setSourceManager (nullptr );
14951498 CI.setFileManager (nullptr );
14961499 if (CI.hasTarget ())
1497- Target = & CI.getTarget ();
1500+ Target = CI.getTargetPtr ();
14981501 Reader = CI.getASTReader ();
14991502 HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure ();
15001503 if (Invocation != CI.getInvocationPtr ()) {
@@ -1544,10 +1547,11 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
15441547 AST->Diagnostics = Diags;
15451548 AST->FileSystemOpts = CI->getFileSystemOpts ();
15461549 AST->Invocation = std::move (CI);
1547- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1550+ AST->FileMgr =
1551+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
15481552 AST->UserFilesAreVolatile = UserFilesAreVolatile;
1549- AST->SourceMgr = new SourceManager (AST-> getDiagnostics (), *AST-> FileMgr ,
1550- UserFilesAreVolatile);
1553+ AST->SourceMgr = llvm::makeIntrusiveRefCnt< SourceManager>(
1554+ AST-> getDiagnostics (), *AST-> FileMgr , UserFilesAreVolatile);
15511555 AST->ModCache = createCrossProcessModuleCache ();
15521556
15531557 return AST;
@@ -1635,10 +1639,10 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
16351639 AST->Reader = nullptr ;
16361640
16371641 // Create a file manager object to provide access to and cache the filesystem.
1638- Clang->setFileManager (& AST->getFileManager ());
1642+ Clang->setFileManager (AST->getFileManagerPtr ());
16391643
16401644 // Create the source manager.
1641- Clang->setSourceManager (& AST->getSourceManager ());
1645+ Clang->setSourceManager (AST->getSourceManagerPtr ());
16421646
16431647 FrontendAction *Act = Action;
16441648
@@ -1732,8 +1736,9 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
17321736 std::shared_ptr<CompilerInvocation> CI,
17331737 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
17341738 std::shared_ptr<DiagnosticOptions> DiagOpts,
1735- IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
1736- bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
1739+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
1740+ IntrusiveRefCntPtr<FileManager> FileMgr, bool OnlyLocalDecls,
1741+ CaptureDiagsKind CaptureDiagnostics,
17371742 unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
17381743 bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
17391744 bool UserFilesAreVolatile) {
@@ -1840,7 +1845,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCommandLine(
18401845 AST->Diagnostics = Diags;
18411846 AST->FileSystemOpts = CI->getFileSystemOpts ();
18421847 VFS = createVFSFromCompilerInvocation (*CI, *Diags, VFS);
1843- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1848+ AST->FileMgr =
1849+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
18441850 AST->StorePreamblesInMemory = StorePreamblesInMemory;
18451851 AST->PreambleStoragePath = PreambleStoragePath;
18461852 AST->ModCache = createCrossProcessModuleCache ();
@@ -2201,7 +2207,8 @@ void ASTUnit::CodeComplete(
22012207 CodeCompleteConsumer &Consumer,
22022208 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
22032209 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diag, LangOptions &LangOpts,
2204- SourceManager &SourceMgr, FileManager &FileMgr,
2210+ llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr,
2211+ llvm::IntrusiveRefCntPtr<FileManager> FileMgr,
22052212 SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
22062213 SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers,
22072214 std::unique_ptr<SyntaxOnlyAction> Act) {
@@ -2256,7 +2263,7 @@ void ASTUnit::CodeComplete(
22562263 Clang->getDiagnostics (),
22572264 &StoredDiagnostics, nullptr );
22582265 ProcessWarningOptions (*Diag, Inv.getDiagnosticOpts (),
2259- FileMgr. getVirtualFileSystem ());
2266+ FileMgr-> getVirtualFileSystem ());
22602267
22612268 // Create the target instance.
22622269 if (!Clang->createTarget ()) {
@@ -2273,8 +2280,8 @@ void ASTUnit::CodeComplete(
22732280 " IR inputs not support here!" );
22742281
22752282 // Use the source and file managers that we were given.
2276- Clang->setFileManager (& FileMgr);
2277- Clang->setSourceManager (& SourceMgr);
2283+ Clang->setFileManager (FileMgr);
2284+ Clang->setSourceManager (SourceMgr);
22782285
22792286 // Remap files.
22802287 PreprocessorOpts.clearRemappedFiles ();
@@ -2292,7 +2299,7 @@ void ASTUnit::CodeComplete(
22922299
22932300 auto getUniqueID =
22942301 [&FileMgr](StringRef Filename) -> std::optional<llvm::sys::fs::UniqueID> {
2295- if (auto Status = FileMgr. getVirtualFileSystem ().status (Filename))
2302+ if (auto Status = FileMgr-> getVirtualFileSystem ().status (Filename))
22962303 return Status->getUniqueID ();
22972304 return std::nullopt ;
22982305 };
@@ -2313,7 +2320,8 @@ void ASTUnit::CodeComplete(
23132320 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
23142321 if (Preamble && Line > 1 && hasSameUniqueID (File, OriginalSourceFile)) {
23152322 OverrideMainBuffer = getMainBufferWithPrecompiledPreamble (
2316- PCHContainerOps, Inv, &FileMgr.getVirtualFileSystem (), false , Line - 1 );
2323+ PCHContainerOps, Inv, FileMgr->getVirtualFileSystemPtr (), false ,
2324+ Line - 1 );
23172325 }
23182326
23192327 // If the main file has been overridden due to the use of a preamble,
@@ -2323,7 +2331,7 @@ void ASTUnit::CodeComplete(
23232331 " No preamble was built, but OverrideMainBuffer is not null" );
23242332
23252333 IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
2326- & FileMgr. getVirtualFileSystem ();
2334+ FileMgr-> getVirtualFileSystemPtr ();
23272335 Preamble->AddImplicitPreamble (Clang->getInvocation (), VFS,
23282336 OverrideMainBuffer.get ());
23292337 // FIXME: there is no way to update VFS if it was changed by
0 commit comments