@@ -831,11 +831,10 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
831
831
AST->CaptureDiagnostics = CaptureDiagnostics;
832
832
AST->DiagOpts = DiagOpts;
833
833
AST->Diagnostics = Diags;
834
- AST->FileMgr = new FileManager (FileSystemOpts, VFS);
834
+ AST->FileMgr = llvm::makeIntrusiveRefCnt< FileManager> (FileSystemOpts, VFS);
835
835
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);
839
838
AST->ModCache = createCrossProcessModuleCache ();
840
839
AST->HSOpts = std::make_unique<HeaderSearchOptions>(HSOpts);
841
840
AST->HSOpts ->ModuleFormat = std::string (PCHContainerRdr.getFormats ().front ());
@@ -858,20 +857,20 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
858
857
Preprocessor &PP = *AST->PP ;
859
858
860
859
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 ());
865
864
866
865
DisableValidationForModuleKind disableValid =
867
866
DisableValidationForModuleKind::None;
868
867
if (::getenv (" LIBCLANG_DISABLE_PCH_VALIDATION" ))
869
868
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);
875
874
876
875
unsigned Counter = 0 ;
877
876
AST->Reader ->setListener (std::make_unique<ASTInfoCollector>(
@@ -1191,9 +1190,11 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1191
1190
// changed above in AddImplicitPreamble. If VFS is nullptr, rely on
1192
1191
// createFileManager to create one.
1193
1192
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
+ }
1197
1198
1198
1199
// Recover resources if we crash before exiting this method.
1199
1200
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
@@ -1226,15 +1227,15 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1226
1227
1227
1228
ResetForParse ();
1228
1229
1229
- SourceMgr = new SourceManager ( getDiagnostics (), *FileMgr,
1230
- UserFilesAreVolatile);
1230
+ SourceMgr = llvm::makeIntrusiveRefCnt< SourceManager>(
1231
+ getDiagnostics (), *FileMgr, + UserFilesAreVolatile);
1231
1232
if (!OverrideMainBuffer) {
1232
1233
checkAndRemoveNonDriverDiags (StoredDiagnostics);
1233
1234
TopLevelDeclsInPreamble.clear ();
1234
1235
}
1235
1236
1236
1237
// Create the source manager.
1237
- Clang->setSourceManager (& getSourceManager ());
1238
+ Clang->setSourceManager (getSourceManagerPtr ());
1238
1239
1239
1240
// If the main file has been overridden due to the use of a preamble,
1240
1241
// make that override happen and introduce the preamble.
@@ -1499,13 +1500,13 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
1499
1500
TheSema = CI.takeSema ();
1500
1501
Consumer = CI.takeASTConsumer ();
1501
1502
if (CI.hasASTContext ())
1502
- Ctx = & CI.getASTContext ();
1503
+ Ctx = CI.getASTContextPtr ();
1503
1504
if (CI.hasPreprocessor ())
1504
1505
PP = CI.getPreprocessorPtr ();
1505
1506
CI.setSourceManager (nullptr );
1506
1507
CI.setFileManager (nullptr );
1507
1508
if (CI.hasTarget ())
1508
- Target = & CI.getTarget ();
1509
+ Target = CI.getTargetPtr ();
1509
1510
Reader = CI.getASTReader ();
1510
1511
HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure ();
1511
1512
if (Invocation != CI.getInvocationPtr ()) {
@@ -1555,10 +1556,11 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
1555
1556
AST->Diagnostics = Diags;
1556
1557
AST->FileSystemOpts = CI->getFileSystemOpts ();
1557
1558
AST->Invocation = std::move (CI);
1558
- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1559
+ AST->FileMgr =
1560
+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
1559
1561
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);
1562
1564
AST->ModCache = createCrossProcessModuleCache ();
1563
1565
1564
1566
return AST;
@@ -1646,10 +1648,10 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
1646
1648
AST->Reader = nullptr ;
1647
1649
1648
1650
// Create a file manager object to provide access to and cache the filesystem.
1649
- Clang->setFileManager (& AST->getFileManager ());
1651
+ Clang->setFileManager (AST->getFileManagerPtr ());
1650
1652
1651
1653
// Create the source manager.
1652
- Clang->setSourceManager (& AST->getSourceManager ());
1654
+ Clang->setSourceManager (AST->getSourceManagerPtr ());
1653
1655
1654
1656
FrontendAction *Act = Action;
1655
1657
@@ -1743,8 +1745,9 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
1743
1745
std::shared_ptr<CompilerInvocation> CI,
1744
1746
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1745
1747
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,
1748
1751
unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
1749
1752
bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
1750
1753
bool UserFilesAreVolatile) {
@@ -1849,7 +1852,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCommandLine(
1849
1852
AST->FileSystemOpts = CI->getFileSystemOpts ();
1850
1853
AST->CodeGenOpts = std::make_unique<CodeGenOptions>(CI->getCodeGenOpts ());
1851
1854
VFS = createVFSFromCompilerInvocation (*CI, *Diags, VFS);
1852
- AST->FileMgr = new FileManager (AST->FileSystemOpts , VFS);
1855
+ AST->FileMgr =
1856
+ llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts , VFS);
1853
1857
AST->StorePreamblesInMemory = StorePreamblesInMemory;
1854
1858
AST->PreambleStoragePath = PreambleStoragePath;
1855
1859
AST->ModCache = createCrossProcessModuleCache ();
@@ -2210,7 +2214,8 @@ void ASTUnit::CodeComplete(
2210
2214
CodeCompleteConsumer &Consumer,
2211
2215
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
2212
2216
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diag, LangOptions &LangOpts,
2213
- SourceManager &SourceMgr, FileManager &FileMgr,
2217
+ llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr,
2218
+ llvm::IntrusiveRefCntPtr<FileManager> FileMgr,
2214
2219
SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
2215
2220
SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers,
2216
2221
std::unique_ptr<SyntaxOnlyAction> Act) {
@@ -2265,7 +2270,7 @@ void ASTUnit::CodeComplete(
2265
2270
Clang->getDiagnostics (),
2266
2271
&StoredDiagnostics, nullptr );
2267
2272
ProcessWarningOptions (*Diag, Inv.getDiagnosticOpts (),
2268
- FileMgr. getVirtualFileSystem ());
2273
+ FileMgr-> getVirtualFileSystem ());
2269
2274
2270
2275
// Create the target instance.
2271
2276
if (!Clang->createTarget ()) {
@@ -2282,8 +2287,8 @@ void ASTUnit::CodeComplete(
2282
2287
" IR inputs not support here!" );
2283
2288
2284
2289
// 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);
2287
2292
2288
2293
// Remap files.
2289
2294
PreprocessorOpts.clearRemappedFiles ();
@@ -2301,7 +2306,7 @@ void ASTUnit::CodeComplete(
2301
2306
2302
2307
auto getUniqueID =
2303
2308
[&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))
2305
2310
return Status->getUniqueID ();
2306
2311
return std::nullopt;
2307
2312
};
@@ -2322,7 +2327,7 @@ void ASTUnit::CodeComplete(
2322
2327
std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
2323
2328
if (Preamble && Line > 1 && hasSameUniqueID (File, OriginalSourceFile)) {
2324
2329
OverrideMainBuffer = getMainBufferWithPrecompiledPreamble (
2325
- PCHContainerOps, Inv, FileMgr. getVirtualFileSystemPtr (), false ,
2330
+ PCHContainerOps, Inv, FileMgr-> getVirtualFileSystemPtr (), false ,
2326
2331
Line - 1 );
2327
2332
}
2328
2333
@@ -2333,7 +2338,7 @@ void ASTUnit::CodeComplete(
2333
2338
" No preamble was built, but OverrideMainBuffer is not null" );
2334
2339
2335
2340
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
2336
- FileMgr. getVirtualFileSystemPtr ();
2341
+ FileMgr-> getVirtualFileSystemPtr ();
2337
2342
Preamble->AddImplicitPreamble (Clang->getInvocation (), VFS,
2338
2343
OverrideMainBuffer.get ());
2339
2344
// FIXME: there is no way to update VFS if it was changed by
0 commit comments