Author: dexonsmith Date: Tue Mar 26 15:32:06 2019 New Revision: 357038 URL: http://llvm.org/viewvc/llvm-project?rev=357038&view=rev Log: Basic: Return a reference from FileManager::getVirtualFileSystem, NFC
FileManager constructs a VFS in its constructor if it isn't passed one, and there's no way to reset it. Make that contract clear by returning a reference from its accessor. https://reviews.llvm.org/D59388 Modified: cfe/trunk/include/clang/Basic/FileManager.h cfe/trunk/include/clang/Frontend/CompilerInstance.h cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/lib/Frontend/CompilerInstance.cpp cfe/trunk/lib/Frontend/FrontendAction.cpp cfe/trunk/lib/Lex/HeaderSearch.cpp cfe/trunk/lib/Lex/ModuleMap.cpp cfe/trunk/lib/Lex/PPLexerChange.cpp cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/lib/Tooling/Tooling.cpp cfe/trunk/unittests/AST/ASTImporterTest.cpp Modified: cfe/trunk/include/clang/Basic/FileManager.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/FileManager.h (original) +++ cfe/trunk/include/clang/Basic/FileManager.h Tue Mar 26 15:32:06 2019 @@ -221,9 +221,7 @@ public: FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; } const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; } - IntrusiveRefCntPtr<llvm::vfs::FileSystem> getVirtualFileSystem() const { - return FS; - } + llvm::vfs::FileSystem &getVirtualFileSystem() const { return *FS; } /// Retrieve a file entry for a "virtual" file that acts as /// if there were a file with the given name on disk. Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original) +++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Tue Mar 26 15:32:06 2019 @@ -380,7 +380,7 @@ public: /// { llvm::vfs::FileSystem &getVirtualFileSystem() const { - return *getFileManager().getVirtualFileSystem(); + return getFileManager().getVirtualFileSystem(); } /// } Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Mar 26 15:32:06 2019 @@ -1079,7 +1079,7 @@ bool ASTUnit::Parse(std::shared_ptr<PCHC return true; if (VFS && FileMgr) - assert(VFS == FileMgr->getVirtualFileSystem() && + assert(VFS == &FileMgr->getVirtualFileSystem() && "VFS passed to Parse and VFS in FileMgr are different"); auto CCInvocation = std::make_shared<CompilerInvocation>(*Invocation); @@ -1097,7 +1097,7 @@ bool ASTUnit::Parse(std::shared_ptr<PCHC // Ensure that Clang has a FileManager with the right VFS, which may have // changed above in AddImplicitPreamble. If VFS is nullptr, rely on // createFileManager to create one. - if (VFS && FileMgr && FileMgr->getVirtualFileSystem() == VFS) + if (VFS && FileMgr && &FileMgr->getVirtualFileSystem() == VFS) Clang->setFileManager(&*FileMgr); else FileMgr = Clang->createFileManager(std::move(VFS)); @@ -1690,7 +1690,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFr if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps), PrecompilePreambleAfterNParses, - AST->FileMgr->getVirtualFileSystem())) + &AST->FileMgr->getVirtualFileSystem())) return nullptr; return AST; } @@ -1797,7 +1797,7 @@ bool ASTUnit::Reparse(std::shared_ptr<PC if (!VFS) { assert(FileMgr && "FileMgr is null on Reparse call"); - VFS = FileMgr->getVirtualFileSystem(); + VFS = &FileMgr->getVirtualFileSystem(); } clearFileLevelDecls(); @@ -2211,18 +2211,18 @@ void ASTUnit::CodeComplete( if (Preamble) { std::string CompleteFilePath(File); - auto VFS = FileMgr.getVirtualFileSystem(); - auto CompleteFileStatus = VFS->status(CompleteFilePath); + auto &VFS = FileMgr.getVirtualFileSystem(); + auto CompleteFileStatus = VFS.status(CompleteFilePath); if (CompleteFileStatus) { llvm::sys::fs::UniqueID CompleteFileID = CompleteFileStatus->getUniqueID(); std::string MainPath(OriginalSourceFile); - auto MainStatus = VFS->status(MainPath); + auto MainStatus = VFS.status(MainPath); if (MainStatus) { llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID(); if (CompleteFileID == MainID && Line > 1) OverrideMainBuffer = getMainBufferWithPrecompiledPreamble( - PCHContainerOps, Inv, VFS, false, Line - 1); + PCHContainerOps, Inv, &VFS, false, Line - 1); } } } @@ -2233,7 +2233,8 @@ void ASTUnit::CodeComplete( assert(Preamble && "No preamble was built, but OverrideMainBuffer is not null"); - auto VFS = FileMgr.getVirtualFileSystem(); + IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = + &FileMgr.getVirtualFileSystem(); Preamble->AddImplicitPreamble(Clang->getInvocation(), VFS, OverrideMainBuffer.get()); // FIXME: there is no way to update VFS if it was changed by Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue Mar 26 15:32:06 2019 @@ -169,7 +169,7 @@ static void collectIncludePCH(CompilerIn std::error_code EC; SmallString<128> DirNative; llvm::sys::path::native(PCHDir->getName(), DirNative); - llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); SimpleASTReaderListener Validator(CI.getPreprocessor()); for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { @@ -296,7 +296,7 @@ CompilerInstance::createDiagnostics(Diag FileManager *CompilerInstance::createFileManager( IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { if (!VFS) - VFS = FileMgr ? FileMgr->getVirtualFileSystem() + VFS = FileMgr ? &FileMgr->getVirtualFileSystem() : createVFSFromCompilerInvocation(getInvocation(), getDiagnostics()); assert(VFS && "FileManager has no VFS?"); Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/FrontendAction.cpp (original) +++ cfe/trunk/lib/Frontend/FrontendAction.cpp Tue Mar 26 15:32:06 2019 @@ -360,7 +360,7 @@ static std::error_code collectModuleHead SmallString<128> DirNative; llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative); - llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); for (llvm::vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End; Dir != End && !EC; Dir.increment(EC)) { // Check whether this entry has an extension typically associated with @@ -714,7 +714,7 @@ bool FrontendAction::BeginSourceFile(Com SmallString<128> DirNative; llvm::sys::path::native(PCHDir->getName(), DirNative); bool Found = false; - llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Lex/HeaderSearch.cpp (original) +++ cfe/trunk/lib/Lex/HeaderSearch.cpp Tue Mar 26 15:32:06 2019 @@ -1579,7 +1579,7 @@ void HeaderSearch::collectAllModules(Sma DirNative); // Search each of the ".framework" directories to load them as modules. - llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { @@ -1650,7 +1650,7 @@ void HeaderSearch::loadSubdirectoryModul FileMgr.makeAbsolutePath(Dir); SmallString<128> DirNative; llvm::sys::path::native(Dir, DirNative); - llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { bool IsFramework = llvm::sys::path::extension(Dir->path()) == ".framework"; Modified: cfe/trunk/lib/Lex/ModuleMap.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Lex/ModuleMap.cpp (original) +++ cfe/trunk/lib/Lex/ModuleMap.cpp Tue Mar 26 15:32:06 2019 @@ -1021,7 +1021,7 @@ Module *ModuleMap::inferFrameworkModule( = StringRef(FrameworkDir->getName()); llvm::sys::path::append(SubframeworksDirName, "Frameworks"); llvm::sys::path::native(SubframeworksDirName); - llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); for (llvm::vfs::directory_iterator Dir = FS.dir_begin(SubframeworksDirName, EC), DirEnd; @@ -2397,7 +2397,7 @@ void ModuleMapParser::parseUmbrellaDirDe std::error_code EC; SmallVector<Module::Header, 6> Headers; llvm::vfs::FileSystem &FS = - *SourceMgr.getFileManager().getVirtualFileSystem(); + SourceMgr.getFileManager().getVirtualFileSystem(); for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E; I != E && !EC; I.increment(EC)) { if (const FileEntry *FE = SourceMgr.getFileManager().getFile(I->path())) { Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Lex/PPLexerChange.cpp (original) +++ cfe/trunk/lib/Lex/PPLexerChange.cpp Tue Mar 26 15:32:06 2019 @@ -270,7 +270,7 @@ void Preprocessor::diagnoseMissingHeader ModuleMap &ModMap = getHeaderSearchInfo().getModuleMap(); const DirectoryEntry *Dir = Mod.getUmbrellaDir().Entry; - llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); std::error_code EC; for (llvm::vfs::recursive_directory_iterator Entry(FS, Dir->getName(), EC), End; Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Mar 26 15:32:06 2019 @@ -8379,7 +8379,8 @@ void Sema::CodeCompleteIncludedFile(llvm // We need the native slashes for the actual file system interactions. SmallString<128> NativeRelDir = StringRef(RelDir); llvm::sys::path::native(NativeRelDir); - auto FS = getSourceManager().getFileManager().getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = + getSourceManager().getFileManager().getVirtualFileSystem(); ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -8425,7 +8426,7 @@ void Sema::CodeCompleteIncludedFile(llvm std::error_code EC; unsigned Count = 0; - for (auto It = FS->dir_begin(Dir, EC); + for (auto It = FS.dir_begin(Dir, EC); !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) { if (++Count == 2500) // If we happen to hit a huge directory, break; // bail out early so we're not too slow. Modified: cfe/trunk/lib/Tooling/Tooling.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/lib/Tooling/Tooling.cpp (original) +++ cfe/trunk/lib/Tooling/Tooling.cpp Tue Mar 26 15:32:06 2019 @@ -301,7 +301,7 @@ bool ToolInvocation::run() { DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); const std::unique_ptr<driver::Driver> Driver( - newDriver(&Diagnostics, BinaryName, Files->getVirtualFileSystem())); + newDriver(&Diagnostics, BinaryName, &Files->getVirtualFileSystem())); // The "input file not found" diagnostics from the driver are useful. // The driver is only aware of the VFS working directory, but some clients // change this at the FileManager level instead. Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=357038&r1=357037&r2=357038&view=diff ============================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original) +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Tue Mar 26 15:32:06 2019 @@ -44,7 +44,7 @@ createVirtualFileIfNeeded(ASTUnit *ToAST assert(ToAST); ASTContext &ToCtx = ToAST->getASTContext(); auto *OFS = static_cast<llvm::vfs::OverlayFileSystem *>( - ToCtx.getSourceManager().getFileManager().getVirtualFileSystem().get()); + &ToCtx.getSourceManager().getFileManager().getVirtualFileSystem()); auto *MFS = static_cast<llvm::vfs::InMemoryFileSystem *>( OFS->overlays_begin()->get()); MFS->addFile(FileName, 0, std::move(Buffer)); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits