Index: include/clang/Frontend/ASTUnit.h =================================================================== --- include/clang/Frontend/ASTUnit.h +++ include/clang/Frontend/ASTUnit.h @@ -522,8 +522,12 @@ return *LangOpts; } - const FileManager &getFileManager() const { return *FileMgr; } - FileManager &getFileManager() { return *FileMgr; } + const IntrusiveRefCntPtr getFileManager() const { + return FileMgr; + } + IntrusiveRefCntPtr getFileManager() { + return FileMgr; + } const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; } @@ -807,7 +811,8 @@ static std::unique_ptr LoadFromCompilerInvocation( CompilerInvocation *CI, std::shared_ptr PCHContainerOps, - IntrusiveRefCntPtr Diags, FileManager *FileMgr, + IntrusiveRefCntPtr Diags, + IntrusiveRefCntPtr FileMgr, bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, unsigned PrecompilePreambleAfterNParses = 0, TranslationUnitKind TUKind = TU_Complete, @@ -888,7 +893,8 @@ CodeCompleteConsumer &Consumer, std::shared_ptr PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, - SourceManager &SourceMgr, FileManager &FileMgr, + SourceManager &SourceMgr, + IntrusiveRefCntPtr FileMgr, SmallVectorImpl &StoredDiagnostics, SmallVectorImpl &OwnedBuffers); Index: include/clang/Frontend/CompilerInstance.h =================================================================== --- include/clang/Frontend/CompilerInstance.h +++ include/clang/Frontend/CompilerInstance.h @@ -401,7 +401,7 @@ } /// \brief Replace the current file manager and virtual file system. - void setFileManager(FileManager *Value); + void setFileManager(IntrusiveRefCntPtr Value); /// } /// @name Source Manager Index: include/clang/Tooling/Tooling.h =================================================================== --- include/clang/Tooling/Tooling.h +++ include/clang/Tooling/Tooling.h @@ -69,7 +69,8 @@ /// \brief Perform an action for an invocation. virtual bool - runInvocation(clang::CompilerInvocation *Invocation, FileManager *Files, + runInvocation(clang::CompilerInvocation *Invocation, + IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps, DiagnosticConsumer *DiagConsumer) = 0; }; @@ -85,7 +86,8 @@ ~FrontendActionFactory() override; /// \brief Invokes the compiler with a FrontendAction created by create(). - bool runInvocation(clang::CompilerInvocation *Invocation, FileManager *Files, + bool runInvocation(clang::CompilerInvocation *Invocation, + IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps, DiagnosticConsumer *DiagConsumer) override; @@ -217,7 +219,7 @@ /// \param PCHContainerOps The PCHContainerOperations for loading and creating /// clang modules. ToolInvocation(std::vector CommandLine, FrontendAction *FAction, - FileManager *Files, + IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps = std::make_shared()); @@ -229,7 +231,7 @@ /// \param PCHContainerOps The PCHContainerOperations for loading and creating /// clang modules. ToolInvocation(std::vector CommandLine, ToolAction *Action, - FileManager *Files, + IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps); ~ToolInvocation(); @@ -262,7 +264,7 @@ std::vector CommandLine; ToolAction *Action; bool OwnsAction; - FileManager *Files; + IntrusiveRefCntPtr Files; std::shared_ptr PCHContainerOps; // Maps -> . llvm::StringMap MappedFileContents; Index: lib/ARCMigrate/ARCMT.cpp =================================================================== --- lib/ARCMigrate/ARCMT.cpp +++ lib/ARCMigrate/ARCMT.cpp @@ -608,7 +608,7 @@ llvm::MemoryBuffer::getMemBufferCopy( StringRef(newText.data(), newText.size()), newFname)); SmallString<64> filePath(file->getName()); - Unit->getFileManager().FixupRelativePath(filePath); + Unit->getFileManager()->FixupRelativePath(filePath); Remapper.remap(filePath.str(), std::move(memBuf)); } Index: lib/Frontend/ASTMerge.cpp =================================================================== --- lib/Frontend/ASTMerge.cpp +++ lib/Frontend/ASTMerge.cpp @@ -55,7 +55,7 @@ ASTImporter Importer(CI.getASTContext(), CI.getFileManager(), Unit->getASTContext(), - Unit->getFileManager(), + *Unit->getFileManager(), /*MinimalImport=*/false); TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); Index: lib/Frontend/ASTUnit.cpp =================================================================== --- lib/Frontend/ASTUnit.cpp +++ lib/Frontend/ASTUnit.cpp @@ -674,7 +674,7 @@ AST->FileMgr = new FileManager(FileSystemOpts, VFS); AST->UserFilesAreVolatile = UserFilesAreVolatile; AST->SourceMgr = new SourceManager(AST->getDiagnostics(), - AST->getFileManager(), + *AST->getFileManager(), UserFilesAreVolatile); AST->HSOpts = new HeaderSearchOptions(); AST->HSOpts->ModuleFormat = PCHContainerRdr.getFormat(); @@ -1100,7 +1100,7 @@ } // Create a file manager object to provide access to and cache the filesystem. - Clang->setFileManager(&getFileManager()); + Clang->setFileManager(getFileManager()); // Create the source manager. Clang->setSourceManager(&getSourceManager()); @@ -1140,7 +1140,7 @@ if (SavedMainFileBuffer) { std::string ModName = getPreambleFile(this); - TranslateStoredDiagnostics(getFileManager(), getSourceManager(), + TranslateStoredDiagnostics(*getFileManager(), getSourceManager(), PreambleDiagnostics, StoredDiagnostics); } @@ -1807,7 +1807,7 @@ AST->Reader = nullptr; // Create a file manager object to provide access to and cache the filesystem. - Clang->setFileManager(&AST->getFileManager()); + Clang->setFileManager(AST->getFileManager()); // Create the source manager. Clang->setSourceManager(&AST->getSourceManager()); @@ -1894,7 +1894,8 @@ std::unique_ptr ASTUnit::LoadFromCompilerInvocation( CompilerInvocation *CI, std::shared_ptr PCHContainerOps, - IntrusiveRefCntPtr Diags, FileManager *FileMgr, + IntrusiveRefCntPtr Diags, + IntrusiveRefCntPtr FileMgr, bool OnlyLocalDecls, bool CaptureDiagnostics, unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, @@ -2312,7 +2313,8 @@ CodeCompleteConsumer &Consumer, std::shared_ptr PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, - FileManager &FileMgr, SmallVectorImpl &StoredDiagnostics, + IntrusiveRefCntPtr FileMgr, + SmallVectorImpl &StoredDiagnostics, SmallVectorImpl &OwnedBuffers) { if (!Invocation) return; @@ -2387,7 +2389,7 @@ // Use the source and file managers that we were given. - Clang->setFileManager(&FileMgr); + Clang->setFileManager(FileMgr); Clang->setSourceManager(&SourceMgr); // Remap files. Index: lib/Frontend/CompilerInstance.cpp =================================================================== --- lib/Frontend/CompilerInstance.cpp +++ lib/Frontend/CompilerInstance.cpp @@ -81,7 +81,7 @@ void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; } void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; } -void CompilerInstance::setFileManager(FileManager *Value) { +void CompilerInstance::setFileManager(IntrusiveRefCntPtr Value) { FileMgr = Value; if (Value) VirtualFileSystem = Value->getVirtualFileSystem(); Index: lib/Frontend/FrontendAction.cpp =================================================================== --- lib/Frontend/FrontendAction.cpp +++ lib/Frontend/FrontendAction.cpp @@ -203,7 +203,7 @@ // Set the shared objects, these are reset when we finish processing the // file, otherwise the CompilerInstance will happily destroy them. - CI.setFileManager(&AST->getFileManager()); + CI.setFileManager(AST->getFileManager()); CI.setSourceManager(&AST->getSourceManager()); CI.setPreprocessor(&AST->getPreprocessor()); CI.setASTContext(&AST->getASTContext()); Index: lib/Tooling/Tooling.cpp =================================================================== --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -125,12 +125,12 @@ SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); - llvm::IntrusiveRefCntPtr OverlayFileSystem( + IntrusiveRefCntPtr OverlayFileSystem( new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr InMemoryFileSystem( + IntrusiveRefCntPtr InMemoryFileSystem( new vfs::InMemoryFileSystem); OverlayFileSystem->pushOverlay(InMemoryFileSystem); - llvm::IntrusiveRefCntPtr Files( + IntrusiveRefCntPtr Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); ToolInvocation Invocation(getSyntaxOnlyToolArgs(Args, FileNameRef), ToolAction, Files.get(), PCHContainerOps); @@ -204,13 +204,13 @@ ToolInvocation::ToolInvocation( std::vector CommandLine, ToolAction *Action, - FileManager *Files, std::shared_ptr PCHContainerOps) + IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps) : CommandLine(std::move(CommandLine)), Action(Action), OwnsAction(false), Files(Files), PCHContainerOps(PCHContainerOps), DiagConsumer(nullptr) {} ToolInvocation::ToolInvocation( std::vector CommandLine, FrontendAction *FAction, - FileManager *Files, std::shared_ptr PCHContainerOps) + IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps) : CommandLine(std::move(CommandLine)), Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true), Files(Files), PCHContainerOps(PCHContainerOps), DiagConsumer(nullptr) {} @@ -279,7 +279,7 @@ } bool FrontendActionFactory::runInvocation( - CompilerInvocation *Invocation, FileManager *Files, + CompilerInvocation *Invocation, IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps, DiagnosticConsumer *DiagConsumer) { // Create a compiler instance to handle the actual work. @@ -442,7 +442,8 @@ public: ASTBuilderAction(std::vector> &ASTs) : ASTs(ASTs) {} - bool runInvocation(CompilerInvocation *Invocation, FileManager *Files, + bool runInvocation(CompilerInvocation *Invocation, + IntrusiveRefCntPtr Files, std::shared_ptr PCHContainerOps, DiagnosticConsumer *DiagConsumer) override { std::unique_ptr AST = ASTUnit::LoadFromCompilerInvocation( Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3495,7 +3495,7 @@ ASTUnit *CXXUnit = cxtu::getASTUnit(TU); - FileManager &FMgr = CXXUnit->getFileManager(); + FileManager &FMgr = *CXXUnit->getFileManager(); return const_cast(FMgr.getFile(file_name)); } @@ -7034,7 +7034,7 @@ if (!CXMod) return 0; Module *Mod = static_cast(CXMod); - FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager(); + FileManager &FileMgr = *cxtu::getASTUnit(TU)->getFileManager(); ArrayRef TopHeaders = Mod->getTopHeaders(FileMgr); return TopHeaders.size(); } @@ -7048,7 +7048,7 @@ if (!CXMod) return nullptr; Module *Mod = static_cast(CXMod); - FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager(); + FileManager &FileMgr = *cxtu::getASTUnit(TU)->getFileManager(); ArrayRef TopHeaders = Mod->getTopHeaders(FileMgr); if (Index < TopHeaders.size()) Index: tools/libclang/CIndexCodeCompletion.cpp =================================================================== --- tools/libclang/CIndexCodeCompletion.cpp +++ tools/libclang/CIndexCodeCompletion.cpp @@ -691,7 +691,7 @@ // Parse the resulting source file to find code-completion results. AllocatedCXCodeCompleteResults *Results = new AllocatedCXCodeCompleteResults( - &AST->getFileManager()); + AST->getFileManager().get()); Results->Results = nullptr; Results->NumResults = 0; @@ -706,7 +706,8 @@ (options & CXCodeComplete_IncludeCodePatterns), IncludeBriefComments, Capture, CXXIdx->getPCHContainerOperations(), *Results->Diag, - Results->LangOpts, *Results->SourceMgr, *Results->FileMgr, + Results->LangOpts, *Results->SourceMgr, + AST->getFileManager(), Results->Diagnostics, Results->TemporaryBuffers); Results->DiagnosticsWrappers.resize(Results->Diagnostics.size()); Index: tools/libclang/Indexing.cpp =================================================================== --- tools/libclang/Indexing.cpp +++ tools/libclang/Indexing.cpp @@ -742,7 +742,7 @@ if (const FileEntry *PCHFile = Unit->getPCHFile()) IndexCtx->importedPCH(PCHFile); - FileManager &FileMgr = Unit->getFileManager(); + FileManager &FileMgr = *Unit->getFileManager(); if (Unit->getOriginalSourceFileName().empty()) IndexCtx->enteredMainFile(nullptr);