Author: James Y Knight Date: 2025-07-31T09:57:13-04:00 New Revision: 9ddbb478ce11e43ae18aa6d04937a51621021482
URL: https://github.com/llvm/llvm-project/commit/9ddbb478ce11e43ae18aa6d04937a51621021482 DIFF: https://github.com/llvm/llvm-project/commit/9ddbb478ce11e43ae18aa6d04937a51621021482.diff LOG: NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for llvm::vfs::FileSystem. (#151407) This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>` instead of `FileSystem*` or `FileSystem&`, when dealing with existing objects. Part of cleanup #151026. Added: Modified: clang/include/clang/Frontend/CompilerInstance.h clang/lib/Basic/SourceManager.cpp clang/lib/CodeGen/CodeGenAction.cpp clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/PrecompiledPreamble.cpp clang/lib/Tooling/Core/Replacement.cpp clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp clang/lib/Tooling/Tooling.cpp clang/tools/clang-format/ClangFormat.cpp clang/tools/clang-import-test/clang-import-test.cpp clang/tools/clang-installapi/ClangInstallAPI.cpp clang/unittests/Analysis/MacroExpansionContextTest.cpp clang/unittests/Basic/FileManagerTest.cpp clang/unittests/Basic/SarifTest.cpp clang/unittests/CodeGen/TestCompiler.h clang/unittests/Driver/DXCModeTest.cpp clang/unittests/Driver/SanitizerArgsTest.cpp clang/unittests/Driver/SimpleDiagnosticConsumer.h clang/unittests/Driver/ToolChainTest.cpp clang/unittests/Frontend/ASTUnitTest.cpp clang/unittests/Frontend/PCHPreambleTest.cpp clang/unittests/Frontend/ReparseWorkingDirTest.cpp clang/unittests/Frontend/SearchPathTest.cpp clang/unittests/Frontend/UtilsTest.cpp clang/unittests/Lex/HeaderSearchTest.cpp clang/unittests/Lex/PPCallbacksTest.cpp clang/unittests/Lex/PPDependencyDirectivesTest.cpp clang/unittests/Support/TimeProfilerTest.cpp clang/unittests/Tooling/CompilationDatabaseTest.cpp clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp clang/unittests/Tooling/RefactoringTest.cpp clang/unittests/Tooling/RewriterTestContext.h clang/unittests/Tooling/Syntax/TokensTest.cpp clang/unittests/Tooling/Syntax/TreeTestBase.h clang/unittests/Tooling/ToolingTest.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp lldb/unittests/Host/FileSystemTest.cpp llvm/include/llvm/Support/VirtualFileSystem.h llvm/lib/Support/FileCollector.cpp llvm/lib/Support/VirtualFileSystem.cpp llvm/unittests/Support/VirtualFileSystemTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 2408367e19833..02dd16c1e96f4 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -420,6 +420,8 @@ class CompilerInstance : public ModuleLoader { /// @{ llvm::vfs::FileSystem &getVirtualFileSystem() const; + llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> + getVirtualFileSystemPtr() const; /// @} /// @name File Manager diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index b2b1488f9dc8e..5b8444a5d2eb7 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -2366,18 +2366,16 @@ size_t SourceManager::getDataStructureSizes() const { SourceManagerForFile::SourceManagerForFile(StringRef FileName, StringRef Content) { - // This is referenced by `FileMgr` and will be released by `FileMgr` when it - // is deleted. - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); InMemoryFileSystem->addFile( FileName, 0, llvm::MemoryBuffer::getMemBuffer(Content, FileName, /*RequiresNullTerminator=*/false)); // This is passed to `SM` as reference, so the pointer has to be referenced // in `Environment` so that `FileMgr` can out-live this function scope. - FileMgr = - std::make_unique<FileManager>(FileSystemOptions(), InMemoryFileSystem); + FileMgr = std::make_unique<FileManager>(FileSystemOptions(), + std::move(InMemoryFileSystem)); DiagOpts = std::make_unique<DiagnosticOptions>(); // This is passed to `SM` as reference, so the pointer has to be referenced // by `Environment` due to the same reason above. diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 2c0767f3d0af6..dc54c97eeae8e 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -978,7 +978,7 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { CI.getPreprocessor()); std::unique_ptr<BackendConsumer> Result(new BackendConsumer( - CI, BA, &CI.getVirtualFileSystem(), *VMContext, std::move(LinkModules), + CI, BA, CI.getVirtualFileSystemPtr(), *VMContext, std::move(LinkModules), InFile, std::move(OS), CoverageInfo)); BEConsumer = Result.get(); @@ -1156,7 +1156,7 @@ void CodeGenAction::ExecuteAction() { // Set clang diagnostic handler. To do this we need to create a fake // BackendConsumer. - BackendConsumer Result(CI, BA, &CI.getVirtualFileSystem(), *VMContext, + BackendConsumer Result(CI, BA, CI.getVirtualFileSystemPtr(), *VMContext, std::move(LinkModules), "", nullptr, nullptr, TheModule.get()); diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp index 95971e57086e7..074f2a520704d 100644 --- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp +++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp @@ -146,7 +146,7 @@ class PCHContainerGenerator : public ASTConsumer { : CI(CI), Diags(CI.getDiagnostics()), MainFileName(MainFileName), OutputFileName(OutputFileName), Ctx(nullptr), MMap(CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()), - FS(&CI.getVirtualFileSystem()), + FS(CI.getVirtualFileSystemPtr()), HeaderSearchOpts(CI.getHeaderSearchOpts()), PreprocessorOpts(CI.getPreprocessorOpts()), TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()), diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 67ed17bdd7b5d..09caf852bd7c4 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1773,7 +1773,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation( if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps), PrecompilePreambleAfterNParses, - &AST->FileMgr->getVirtualFileSystem())) + AST->FileMgr->getVirtualFileSystemPtr())) return nullptr; return AST; } @@ -1895,7 +1895,7 @@ bool ASTUnit::Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, if (!VFS) { assert(FileMgr && "FileMgr is null on Reparse call"); - VFS = &FileMgr->getVirtualFileSystem(); + VFS = FileMgr->getVirtualFileSystemPtr(); } clearFileLevelDecls(); @@ -2321,7 +2321,8 @@ void ASTUnit::CodeComplete( std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer; if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) { OverrideMainBuffer = getMainBufferWithPrecompiledPreamble( - PCHContainerOps, Inv, &FileMgr.getVirtualFileSystem(), false, Line - 1); + PCHContainerOps, Inv, FileMgr.getVirtualFileSystemPtr(), false, + Line - 1); } // If the main file has been overridden due to the use of a preamble, @@ -2331,7 +2332,7 @@ void ASTUnit::CodeComplete( "No preamble was built, but OverrideMainBuffer is not null"); IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = - &FileMgr.getVirtualFileSystem(); + FileMgr.getVirtualFileSystemPtr(); Preamble->AddImplicitPreamble(Clang->getInvocation(), VFS, OverrideMainBuffer.get()); // FIXME: there is no way to update VFS if it was changed by diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index c7b82db292a14..40fb070e5f6cf 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -160,6 +160,11 @@ llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const { return getFileManager().getVirtualFileSystem(); } +llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> +CompilerInstance::getVirtualFileSystemPtr() const { + return getFileManager().getVirtualFileSystemPtr(); +} + void CompilerInstance::setFileManager(FileManager *Value) { FileMgr = Value; } @@ -375,7 +380,7 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics( FileManager *CompilerInstance::createFileManager( IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { if (!VFS) - VFS = FileMgr ? &FileMgr->getVirtualFileSystem() + VFS = FileMgr ? FileMgr->getVirtualFileSystemPtr() : createVFSFromCompilerInvocation(getInvocation(), getDiagnostics()); assert(VFS && "FileManager has no VFS?"); @@ -1218,7 +1223,7 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl( } else if (FrontendOpts.ModulesShareFileManager) { Instance.setFileManager(&getFileManager()); } else { - Instance.createFileManager(&getVirtualFileSystem()); + Instance.createFileManager(getVirtualFileSystemPtr()); } if (ThreadSafeConfig) { diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index 146cf903a5727..486cd95962efe 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -57,11 +57,9 @@ createVFSOverlayForPreamblePCH(StringRef PCHFilename, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { // We want only the PCH file from the real filesystem to be available, // so we create an in-memory VFS with just that and overlay it on top. - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> PCHFS( - new llvm::vfs::InMemoryFileSystem()); + auto PCHFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); PCHFS->addFile(PCHFilename, 0, std::move(PCHBuffer)); - IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> Overlay( - new llvm::vfs::OverlayFileSystem(VFS)); + auto Overlay = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(VFS); Overlay->pushOverlay(PCHFS); return Overlay; } diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp index 1506218d88553..a3214de5dc80d 100644 --- a/clang/lib/Tooling/Core/Replacement.cpp +++ b/clang/lib/Tooling/Core/Replacement.cpp @@ -581,8 +581,8 @@ llvm::Expected<std::string> applyAllReplacements(StringRef Code, if (Replaces.empty()) return Code.str(); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager Files(FileSystemOptions(), InMemoryFileSystem); DiagnosticOptions DiagOpts; DiagnosticsEngine Diagnostics( diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index 8ce2706cb1062..b2b61de790e8f 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -605,8 +605,8 @@ DependencyScanningWorker::DependencyScanningWorker( switch (Service.getMode()) { case ScanningMode::DependencyDirectivesScan: - DepFS = - new DependencyScanningWorkerFilesystem(Service.getSharedCache(), FS); + DepFS = llvm::makeIntrusiveRefCnt<DependencyScanningWorkerFilesystem>( + Service.getSharedCache(), FS); BaseFS = DepFS; break; case ScanningMode::CanonicalPreprocessing: diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp index 53339566e310e..ecafe269e9542 100644 --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -227,10 +227,11 @@ bool runToolOnCodeWithArgs( const Twine &ToolName, std::shared_ptr<PCHContainerOperations> PCHContainerOps, const FileContentMappings &VirtualMappedFiles) { - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); SmallString<1024> CodeStorage; @@ -403,7 +404,7 @@ bool ToolInvocation::run() { } const std::unique_ptr<driver::Driver> Driver( - newDriver(&*Diagnostics, BinaryName, &Files->getVirtualFileSystem())); + newDriver(&*Diagnostics, BinaryName, Files->getVirtualFileSystemPtr())); // 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. @@ -473,8 +474,10 @@ ClangTool::ClangTool(const CompilationDatabase &Compilations, IntrusiveRefCntPtr<FileManager> Files) : Compilations(Compilations), SourcePaths(SourcePaths), PCHContainerOps(std::move(PCHContainerOps)), - OverlayFileSystem(new llvm::vfs::OverlayFileSystem(std::move(BaseFS))), - InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem), + OverlayFileSystem(llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + std::move(BaseFS))), + InMemoryFileSystem( + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), Files(Files ? Files : new FileManager(FileSystemOptions(), OverlayFileSystem)) { OverlayFileSystem->pushOverlay(InMemoryFileSystem); @@ -692,10 +695,11 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs( IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) { std::vector<std::unique_ptr<ASTUnit>> ASTs; ASTBuilderAction Action(ASTs); - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(std::move(BaseFS))); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + std::move(BaseFS)); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 24ad3cb42254d..afc40e96dedd6 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -237,8 +237,8 @@ static bool parseLineRange(StringRef Input, unsigned &FromLine, static bool fillRanges(MemoryBuffer *Code, std::vector<tooling::Range> &Ranges) { - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager Files(FileSystemOptions(), InMemoryFileSystem); DiagnosticOptions DiagOpts; DiagnosticsEngine Diagnostics( @@ -511,8 +511,8 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) { if (OutputXML) { outputXML(Replaces, FormatChanges, Status, Cursor, CursorPosition); } else { - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager Files(FileSystemOptions(), InMemoryFileSystem); DiagnosticOptions DiagOpts; diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index 7f5df9259889b..ab021a51bf295 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -236,7 +236,7 @@ std::unique_ptr<CodeGenerator> BuildCodeGen(CompilerInstance &CI, llvm::LLVMContext &LLVMCtx) { StringRef ModuleName("$__module"); return std::unique_ptr<CodeGenerator>(CreateLLVMCodeGen( - CI.getDiagnostics(), ModuleName, &CI.getVirtualFileSystem(), + CI.getDiagnostics(), ModuleName, CI.getVirtualFileSystemPtr(), CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getCodeGenOpts(), LLVMCtx)); } diff --git a/clang/tools/clang-installapi/ClangInstallAPI.cpp b/clang/tools/clang-installapi/ClangInstallAPI.cpp index 60e9fc4354be4..509934e70f04c 100644 --- a/clang/tools/clang-installapi/ClangInstallAPI.cpp +++ b/clang/tools/clang-installapi/ClangInstallAPI.cpp @@ -83,10 +83,11 @@ static bool run(ArrayRef<const char *> Args, const char *ProgName) { // Create file manager for all file operations and holding in-memory generated // inputs. - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); IntrusiveRefCntPtr<clang::FileManager> FM( new FileManager(clang::FileSystemOptions(), OverlayFileSystem)); diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp b/clang/unittests/Analysis/MacroExpansionContextTest.cpp index 9874ea687f3ed..af7a8d6c028ce 100644 --- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp +++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp @@ -33,7 +33,8 @@ namespace { class MacroExpansionContextTest : public ::testing::Test { protected: MacroExpansionContextTest() - : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem), + : InMemoryFileSystem( + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), FileMgr(FileSystemOptions(), InMemoryFileSystem), DiagID(new DiagnosticIDs()), Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()), diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index 88d778fccd68e..7b3e8bc9313ca 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -454,8 +454,7 @@ TEST_F(FileManagerTest, makeAbsoluteUsesVFS) { : StringRef("/"); llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path"); - auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); // setCurrentworkingdirectory must finish without error. ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir)); @@ -475,8 +474,7 @@ TEST_F(FileManagerTest, makeAbsoluteUsesVFS) { TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) { SmallString<64> CustomWorkingDir = getSystemRoot(); - auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); // setCurrentworkingdirectory must finish without error. ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir)); @@ -501,8 +499,7 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) { TEST_F(FileManagerTest, getFileDontOpenRealPath) { SmallString<64> CustomWorkingDir = getSystemRoot(); - auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); // setCurrentworkingdirectory must finish without error. ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir)); @@ -533,8 +530,7 @@ TEST_F(FileManagerTest, getBypassFile) { CustomWorkingDir = "/"; #endif - auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); // setCurrentworkingdirectory must finish without error. ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir)); diff --git a/clang/unittests/Basic/SarifTest.cpp b/clang/unittests/Basic/SarifTest.cpp index ad9f8ecc208a4..c6be7eec12fdd 100644 --- a/clang/unittests/Basic/SarifTest.cpp +++ b/clang/unittests/Basic/SarifTest.cpp @@ -41,7 +41,8 @@ static std::string serializeSarifDocument(llvm::json::Object &&Doc) { class SarifDocumentWriterTest : public ::testing::Test { protected: SarifDocumentWriterTest() - : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem), + : InMemoryFileSystem( + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), FileMgr(FileSystemOptions(), InMemoryFileSystem), DiagID(new DiagnosticIDs()), Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()), diff --git a/clang/unittests/CodeGen/TestCompiler.h b/clang/unittests/CodeGen/TestCompiler.h index a6fec7fb0945d..f6fada5f8a1f0 100644 --- a/clang/unittests/CodeGen/TestCompiler.h +++ b/clang/unittests/CodeGen/TestCompiler.h @@ -58,7 +58,7 @@ struct TestCompiler { CG.reset(CreateLLVMCodeGen( compiler.getDiagnostics(), "main-module", - &compiler.getVirtualFileSystem(), compiler.getHeaderSearchOpts(), + compiler.getVirtualFileSystemPtr(), compiler.getHeaderSearchOpts(), compiler.getPreprocessorOpts(), compiler.getCodeGenOpts(), Context)); } diff --git a/clang/unittests/Driver/DXCModeTest.cpp b/clang/unittests/Driver/DXCModeTest.cpp index f6845939d04b4..3a2e9ece97c27 100644 --- a/clang/unittests/Driver/DXCModeTest.cpp +++ b/clang/unittests/Driver/DXCModeTest.cpp @@ -57,8 +57,8 @@ static void validateTargetProfile( TEST(DxcModeTest, TargetProfileValidation) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); InMemoryFileSystem->addFile("foo.hlsl", 0, llvm::MemoryBuffer::getMemBuffer("\n")); @@ -107,8 +107,8 @@ TEST(DxcModeTest, TargetProfileValidation) { TEST(DxcModeTest, ValidatorVersionValidation) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); InMemoryFileSystem->addFile("foo.hlsl", 0, llvm::MemoryBuffer::getMemBuffer("\n")); @@ -210,8 +210,8 @@ TEST(DxcModeTest, ValidatorVersionValidation) { } TEST(DxcModeTest, DefaultEntry) { - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); InMemoryFileSystem->addFile("foo.hlsl", 0, llvm::MemoryBuffer::getMemBuffer("\n")); diff --git a/clang/unittests/Driver/SanitizerArgsTest.cpp b/clang/unittests/Driver/SanitizerArgsTest.cpp index b8bfc6806da6d..41884c0c62318 100644 --- a/clang/unittests/Driver/SanitizerArgsTest.cpp +++ b/clang/unittests/Driver/SanitizerArgsTest.cpp @@ -78,8 +78,7 @@ class SanitizerArgsTest : public ::testing::Test { private: llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> prepareFS(llvm::ArrayRef<std::string> ExtraFiles) { - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS = - new llvm::vfs::InMemoryFileSystem; + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FS->addFile(ClangBinary, time_t(), llvm::MemoryBuffer::getMemBuffer("")); FS->addFile(InputFile, time_t(), llvm::MemoryBuffer::getMemBuffer("")); for (llvm::StringRef F : ExtraFiles) diff --git a/clang/unittests/Driver/SimpleDiagnosticConsumer.h b/clang/unittests/Driver/SimpleDiagnosticConsumer.h index c3772baade566..a90524c6e33a8 100644 --- a/clang/unittests/Driver/SimpleDiagnosticConsumer.h +++ b/clang/unittests/Driver/SimpleDiagnosticConsumer.h @@ -44,8 +44,8 @@ struct SimpleDiagnosticConsumer : public clang::DiagnosticConsumer { inline clang::driver::Driver diagnostic_test_driver() { llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID( new clang::DiagnosticIDs()); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); auto *DiagConsumer = new SimpleDiagnosticConsumer; clang::DiagnosticOptions DiagOpts; clang::DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer); diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp index 670090a01b0d3..03f2fcfbd7ddf 100644 --- a/clang/unittests/Driver/ToolChainTest.cpp +++ b/clang/unittests/Driver/ToolChainTest.cpp @@ -42,8 +42,8 @@ TEST(ToolChainTest, VFSGCCInstallation) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); const char *EmptyFiles[] = { "foo.cpp", @@ -140,8 +140,8 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags, "clang LLVM compiler", InMemoryFileSystem); @@ -178,8 +178,8 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); const char *EmptyFiles[] = { // Sort entries so the latest version doesn't come first. @@ -342,8 +342,8 @@ TEST(ToolChainTest, VFSGnuLibcxxPathNoSysroot) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); const char *EmptyFiles[] = { "foo.cpp", @@ -374,8 +374,8 @@ TEST(ToolChainTest, DefaultDriverMode) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags, "clang LLVM compiler", InMemoryFileSystem); @@ -520,8 +520,8 @@ TEST(ToolChainTest, CommandOutput) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags, "clang LLVM compiler", InMemoryFileSystem); @@ -548,8 +548,8 @@ TEST(ToolChainTest, PostCallback) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); // The executable path must not exist. Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags, @@ -601,8 +601,8 @@ TEST(ToolChainTest, UEFIDefaultDebugFormatTest) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); Driver CCDriver("/home/test/bin/clang", "x86_64-unknown-uefi", Diags, "clang LLVM compiler", InMemoryFileSystem); CCDriver.setCheckInputsExist(false); @@ -643,8 +643,7 @@ TEST(ToolChainTest, ConfigFileSearch) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); #ifdef _WIN32 const char *TestRoot = "C:\\"; @@ -721,7 +720,7 @@ TEST(ToolChainTest, ConfigFileError) { std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer( new SimpleDiagnosticConsumer()); DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false); - IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS(new FileSystemWithError); + auto FS = llvm::makeIntrusiveRefCnt<FileSystemWithError>(); Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags, "clang LLVM compiler", FS); @@ -742,8 +741,7 @@ TEST(ToolChainTest, BadConfigFile) { std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer( new SimpleDiagnosticConsumer()); DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); #ifdef _WIN32 const char *TestRoot = "C:\\"; @@ -816,8 +814,7 @@ TEST(ToolChainTest, ConfigInexistentInclude) { std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer( new SimpleDiagnosticConsumer()); DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); #ifdef _WIN32 const char *TestRoot = "C:\\"; @@ -857,8 +854,7 @@ TEST(ToolChainTest, ConfigRecursiveInclude) { std::unique_ptr<SimpleDiagnosticConsumer> DiagConsumer( new SimpleDiagnosticConsumer()); DiagnosticsEngine Diags(DiagID, DiagOpts, DiagConsumer.get(), false); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); #ifdef _WIN32 const char *TestRoot = "C:\\"; @@ -902,8 +898,7 @@ TEST(ToolChainTest, NestedConfigFile) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, DiagOpts, new TestDiagnosticConsumer); - IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS( - new llvm::vfs::InMemoryFileSystem); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); #ifdef _WIN32 const char *TestRoot = "C:\\"; diff --git a/clang/unittests/Frontend/ASTUnitTest.cpp b/clang/unittests/Frontend/ASTUnitTest.cpp index afa64b5e90a6d..7148ca03e0aed 100644 --- a/clang/unittests/Frontend/ASTUnitTest.cpp +++ b/clang/unittests/Frontend/ASTUnitTest.cpp @@ -119,8 +119,7 @@ TEST_F(ASTUnitTest, GetBufferForFileMemoryMapping) { } TEST_F(ASTUnitTest, ModuleTextualHeader) { - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFs = - new llvm::vfs::InMemoryFileSystem(); + auto InMemoryFs = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); InMemoryFs->addFile("test.cpp", 0, llvm::MemoryBuffer::getMemBuffer(R"cpp( #include "Textual.h" void foo() {} diff --git a/clang/unittests/Frontend/PCHPreambleTest.cpp b/clang/unittests/Frontend/PCHPreambleTest.cpp index faad408193f62..d27f793a52a7a 100644 --- a/clang/unittests/Frontend/PCHPreambleTest.cpp +++ b/clang/unittests/Frontend/PCHPreambleTest.cpp @@ -62,7 +62,7 @@ class PCHPreambleTest : public ::testing::Test { void TearDown() override {} void ResetVFS() { - VFS = new ReadCountingInMemoryFileSystem(); + VFS = llvm::makeIntrusiveRefCnt<ReadCountingInMemoryFileSystem>(); // We need the working directory to be set to something absolute, // otherwise it ends up being inadvertently set to the current // working directory in the real file system due to a series of diff --git a/clang/unittests/Frontend/ReparseWorkingDirTest.cpp b/clang/unittests/Frontend/ReparseWorkingDirTest.cpp index 1b8051f80e9b8..38ef4686e7d91 100644 --- a/clang/unittests/Frontend/ReparseWorkingDirTest.cpp +++ b/clang/unittests/Frontend/ReparseWorkingDirTest.cpp @@ -28,7 +28,9 @@ class ReparseWorkingDirTest : public ::testing::Test { std::shared_ptr<PCHContainerOperations> PCHContainerOpts; public: - void SetUp() override { VFS = new vfs::InMemoryFileSystem(); } + void SetUp() override { + VFS = llvm::makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); + } void TearDown() override {} void setWorkingDirectory(StringRef Path) { diff --git a/clang/unittests/Frontend/SearchPathTest.cpp b/clang/unittests/Frontend/SearchPathTest.cpp index c74a5c75fada5..014f482d2213c 100644 --- a/clang/unittests/Frontend/SearchPathTest.cpp +++ b/clang/unittests/Frontend/SearchPathTest.cpp @@ -41,7 +41,7 @@ class SearchPathTest : public ::testing::Test { protected: SearchPathTest() : Diags(new DiagnosticIDs(), DiagOpts, new IgnoringDiagConsumer()), - VFS(new llvm::vfs::InMemoryFileSystem), + VFS(llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), FileMgr(FileSystemOptions(), VFS), SourceMgr(Diags, FileMgr), Invocation(std::make_unique<CompilerInvocation>()) {} diff --git a/clang/unittests/Frontend/UtilsTest.cpp b/clang/unittests/Frontend/UtilsTest.cpp index cf385a5323c61..fc411e4af705f 100644 --- a/clang/unittests/Frontend/UtilsTest.cpp +++ b/clang/unittests/Frontend/UtilsTest.cpp @@ -29,7 +29,7 @@ TEST(BuildCompilerInvocationTest, RecoverMultipleJobs) { clang::DiagnosticOptions DiagOpts; CreateInvocationOptions Opts; Opts.RecoverOnError = true; - Opts.VFS = new llvm::vfs::InMemoryFileSystem(); + Opts.VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); Opts.Diags = clang::CompilerInstance::createDiagnostics(*Opts.VFS, DiagOpts, &D, false); std::unique_ptr<CompilerInvocation> CI = createInvocation(Args, Opts); diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index 9903c1246d33d..45eb8559216d9 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -28,8 +28,8 @@ namespace { class HeaderSearchTest : public ::testing::Test { protected: HeaderSearchTest() - : VFS(new llvm::vfs::InMemoryFileSystem), FileMgr(FileMgrOpts, VFS), - DiagID(new DiagnosticIDs()), + : VFS(llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), + FileMgr(FileMgrOpts, VFS), DiagID(new DiagnosticIDs()), Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions), Search(HSOpts, SourceMgr, Diags, LangOpts, Target.get()) { diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp index af86c1888f2c7..a186246909f69 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -133,7 +133,8 @@ class PragmaMarkCallbacks : public PPCallbacks { class PPCallbacksTest : public ::testing::Test { protected: PPCallbacksTest() - : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem), + : InMemoryFileSystem( + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), FileMgr(FileSystemOptions(), InMemoryFileSystem), DiagID(new DiagnosticIDs()), Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()), diff --git a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp index 061cb136a552a..dec22a28cc691 100644 --- a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp +++ b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp @@ -75,7 +75,7 @@ TEST_F(PPDependencyDirectivesTest, MacroGuard) { // "head2.h" and "head3.h" have tokens following the macro check, they should // be included multiple times. - auto VFS = new llvm::vfs::InMemoryFileSystem(); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); VFS->addFile( "head1.h", 0, llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n")); diff --git a/clang/unittests/Support/TimeProfilerTest.cpp b/clang/unittests/Support/TimeProfilerTest.cpp index 85d36b5d21423..f70149daad295 100644 --- a/clang/unittests/Support/TimeProfilerTest.cpp +++ b/clang/unittests/Support/TimeProfilerTest.cpp @@ -46,8 +46,7 @@ std::string teardownProfiler() { bool compileFromString(StringRef Code, StringRef Standard, StringRef File, llvm::StringMap<std::string> Headers = {}) { - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS( - new llvm::vfs::InMemoryFileSystem()); + auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FS->addFile(File, 0, MemoryBuffer::getMemBuffer(Code)); for (const auto &Header : Headers) { FS->addFile(Header.getKey(), 0, diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index c1febaf40bf19..2d68e0994c93e 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -971,7 +971,8 @@ TEST_F(TargetAndModeTest, TargetAndMode) { class ExpandResponseFilesTest : public MemDBTest { public: - ExpandResponseFilesTest() : FS(new llvm::vfs::InMemoryFileSystem) {} + ExpandResponseFilesTest() + : FS(llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()) {} protected: void addFile(StringRef File, StringRef Content) { diff --git a/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp index 1cdb5397aa577..b16dd8e6e2b8f 100644 --- a/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp +++ b/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp @@ -85,7 +85,7 @@ TEST(DependencyScanner, ScanDepsReuseFilemanager) { StringRef CWD = "/root"; FixedCompilationDatabase CDB(CWD, Compilation); - auto VFS = new llvm::vfs::InMemoryFileSystem(); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); std::string HeaderPath = @@ -134,7 +134,7 @@ TEST(DependencyScanner, ScanDepsReuseFilemanagerSkippedFile) { StringRef CWD = "/root"; FixedCompilationDatabase CDB(CWD, Compilation); - auto VFS = new llvm::vfs::InMemoryFileSystem(); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); std::string HeaderPath = @@ -176,7 +176,7 @@ TEST(DependencyScanner, ScanDepsReuseFilemanagerHasInclude) { StringRef CWD = "/root"; FixedCompilationDatabase CDB(CWD, Compilation); - auto VFS = new llvm::vfs::InMemoryFileSystem(); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); std::string HeaderPath = @@ -218,7 +218,7 @@ TEST(DependencyScanner, ScanDepsWithFS) { "test.cpp.o"}; StringRef CWD = "/root"; - auto VFS = new llvm::vfs::InMemoryFileSystem(); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); std::string HeaderPath = @@ -256,7 +256,7 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) { }; StringRef CWD = "/root"; - auto VFS = new llvm::vfs::InMemoryFileSystem(); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); std::string OtherPath = @@ -306,7 +306,7 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) { TEST(DependencyScanner, ScanDepsWithDiagConsumer) { StringRef CWD = "/root"; - auto VFS = new llvm::vfs::InMemoryFileSystem(); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); std::string HeaderPath = diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index 35d114343b517..aff7523e7b340 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -1035,8 +1035,7 @@ static constexpr bool usesWindowsPaths() { TEST(DeduplicateByFileTest, PathsWithDots) { std::map<std::string, Replacements> FileToReplaces; - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( - new llvm::vfs::InMemoryFileSystem()); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager FileMgr(FileSystemOptions(), VFS); StringRef Path1 = usesWindowsPaths() ? "a\\b\\..\\.\\c.h" : "a/b/.././c.h"; StringRef Path2 = usesWindowsPaths() ? "a\\c.h" : "a/c.h"; @@ -1051,8 +1050,7 @@ TEST(DeduplicateByFileTest, PathsWithDots) { TEST(DeduplicateByFileTest, PathWithDotSlash) { std::map<std::string, Replacements> FileToReplaces; - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( - new llvm::vfs::InMemoryFileSystem()); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager FileMgr(FileSystemOptions(), VFS); StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h"; StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h"; @@ -1067,8 +1065,7 @@ TEST(DeduplicateByFileTest, PathWithDotSlash) { TEST(DeduplicateByFileTest, NonExistingFilePath) { std::map<std::string, Replacements> FileToReplaces; - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( - new llvm::vfs::InMemoryFileSystem()); + auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager FileMgr(FileSystemOptions(), VFS); StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h"; StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h"; diff --git a/clang/unittests/Tooling/RewriterTestContext.h b/clang/unittests/Tooling/RewriterTestContext.h index 2d697e276c5e8..c478b3f7d5cfa 100644 --- a/clang/unittests/Tooling/RewriterTestContext.h +++ b/clang/unittests/Tooling/RewriterTestContext.h @@ -51,9 +51,11 @@ class RewriterTestContext { RewriterTestContext() : Diagnostics(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts), - InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem), + InMemoryFileSystem( + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())), + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem())), Files(FileSystemOptions(), OverlayFileSystem), Sources(Diagnostics, Files), Rewrite(Sources, Options) { Diagnostics.setClient(&DiagnosticPrinter, false); diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp b/clang/unittests/Tooling/Syntax/TokensTest.cpp index b5f44454e862d..a643738157035 100644 --- a/clang/unittests/Tooling/Syntax/TokensTest.cpp +++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp @@ -252,7 +252,7 @@ class TokenCollectorTest : public ::testing::Test { llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags = new DiagnosticsEngine(new DiagnosticIDs, DiagOpts); IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS = - new llvm::vfs::InMemoryFileSystem; + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); llvm::IntrusiveRefCntPtr<FileManager> FileMgr = new FileManager(FileSystemOptions(), FS); llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr = diff --git a/clang/unittests/Tooling/Syntax/TreeTestBase.h b/clang/unittests/Tooling/Syntax/TreeTestBase.h index 6110cffa708d9..01ff07b2f5ea6 100644 --- a/clang/unittests/Tooling/Syntax/TreeTestBase.h +++ b/clang/unittests/Tooling/Syntax/TreeTestBase.h @@ -44,7 +44,7 @@ class SyntaxTreeTest : public ::testing::Test, IntrusiveRefCntPtr<DiagnosticsEngine> Diags = new DiagnosticsEngine(new DiagnosticIDs, DiagOpts); IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS = - new llvm::vfs::InMemoryFileSystem; + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); IntrusiveRefCntPtr<FileManager> FileMgr = new FileManager(FileSystemOptions(), FS); IntrusiveRefCntPtr<SourceManager> SourceMgr = diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index 32af4b6b3b359..c72676f83e6ba 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -153,8 +153,8 @@ TEST(buildASTFromCode, ReportsErrors) { } TEST(buildASTFromCode, FileSystem) { - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); InMemoryFileSystem->addFile("included_file.h", 0, llvm::MemoryBuffer::getMemBufferCopy("class X;")); std::unique_ptr<ASTUnit> AST = buildASTFromCodeWithArgs( @@ -188,10 +188,11 @@ TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromFactoryType) { } TEST(ToolInvocation, TestMapVirtualFile) { - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); @@ -214,10 +215,11 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { // mapped module.modulemap is found on the include path. In the future, expand // this test to run a full modules enabled compilation, so we make sure we can // rerun modules compilations with a virtual file system. - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); @@ -240,10 +242,11 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { } TEST(ToolInvocation, DiagnosticsEngineProperlyInitializedForCC1Construction) { - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); @@ -269,10 +272,11 @@ TEST(ToolInvocation, DiagnosticsEngineProperlyInitializedForCC1Construction) { } TEST(ToolInvocation, CustomDiagnosticOptionsOverwriteParsedOnes) { - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); @@ -315,10 +319,11 @@ struct DiagnosticConsumerExpectingSourceManager : public DiagnosticConsumer { }; TEST(ToolInvocation, DiagConsumerExpectingSourceManager) { - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); @@ -341,10 +346,11 @@ TEST(ToolInvocation, DiagConsumerExpectingSourceManager) { } TEST(ToolInvocation, CC1Args) { - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); @@ -361,10 +367,11 @@ TEST(ToolInvocation, CC1Args) { } TEST(ToolInvocation, CC1ArgsInvalid) { - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); llvm::IntrusiveRefCntPtr<FileManager> Files( new FileManager(FileSystemOptions(), OverlayFileSystem)); @@ -398,7 +405,7 @@ struct CommandLineExtractorTest : public ::testing::Test { public: CommandLineExtractorTest() - : InMemoryFS(new llvm::vfs::InMemoryFileSystem), + : InMemoryFS(llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>()), Diags(CompilerInstance::createDiagnostics(*InMemoryFS, DiagOpts)), Driver("clang", llvm::sys::getDefaultTargetTriple(), *Diags, "clang LLVM compiler", overlayRealFS(InMemoryFS)) {} @@ -755,10 +762,11 @@ TEST(ClangToolTest, NoOutputCommands) { TEST(ClangToolTest, BaseVirtualFileSystemUsage) { FixedCompilationDatabase Compilations("/", std::vector<std::string>()); - llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( - new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( - new llvm::vfs::InMemoryFileSystem); + auto OverlayFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( + llvm::vfs::getRealFileSystem()); + auto InMemoryFileSystem = + llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); OverlayFileSystem->pushOverlay(InMemoryFileSystem); InMemoryFileSystem->addFile( diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index 3995bc002cfe0..e5a1d2db604c8 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -894,7 +894,7 @@ ClangExpressionParser::ClangExpressionParser( m_llvm_context = std::make_unique<LLVMContext>(); m_code_generator.reset(CreateLLVMCodeGen( m_compiler->getDiagnostics(), module_name, - &m_compiler->getVirtualFileSystem(), m_compiler->getHeaderSearchOpts(), + m_compiler->getVirtualFileSystemPtr(), m_compiler->getHeaderSearchOpts(), m_compiler->getPreprocessorOpts(), m_compiler->getCodeGenOpts(), *m_llvm_context)); } diff --git a/lldb/unittests/Host/FileSystemTest.cpp b/lldb/unittests/Host/FileSystemTest.cpp index 58887f6b2467e..e3c2b5a5ab49e 100644 --- a/lldb/unittests/Host/FileSystemTest.cpp +++ b/lldb/unittests/Host/FileSystemTest.cpp @@ -186,7 +186,7 @@ TEST(FileSystemTest, FileAndDirectoryComponents) { } static IntrusiveRefCntPtr<DummyFileSystem> GetSimpleDummyFS() { - IntrusiveRefCntPtr<DummyFileSystem> D(new DummyFileSystem()); + auto D = makeIntrusiveRefCnt<DummyFileSystem>(); D->addRegularFile("/foo"); D->addDirectory("/bar"); D->addSymlink("/baz"); diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h index 734b79572164b..d97677305a39f 100644 --- a/llvm/include/llvm/Support/VirtualFileSystem.h +++ b/llvm/include/llvm/Support/VirtualFileSystem.h @@ -1069,7 +1069,7 @@ class LLVM_ABI RedirectingFileSystem /// Redirect each of the remapped files from first to second. static std::unique_ptr<RedirectingFileSystem> create(ArrayRef<std::pair<std::string, std::string>> RemappedFiles, - bool UseExternalNames, FileSystem &ExternalFS); + bool UseExternalNames, IntrusiveRefCntPtr<FileSystem> ExternalFS); ErrorOr<Status> status(const Twine &Path) override; bool exists(const Twine &Path) override; diff --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp index 29436f85c2f23..edb5313d43eec 100644 --- a/llvm/lib/Support/FileCollector.cpp +++ b/llvm/lib/Support/FileCollector.cpp @@ -313,5 +313,6 @@ class FileCollectorFileSystem : public vfs::FileSystem { IntrusiveRefCntPtr<vfs::FileSystem> FileCollector::createCollectorVFS(IntrusiveRefCntPtr<vfs::FileSystem> BaseFS, std::shared_ptr<FileCollector> Collector) { - return new FileCollectorFileSystem(std::move(BaseFS), std::move(Collector)); + return makeIntrusiveRefCnt<FileCollectorFileSystem>(std::move(BaseFS), + std::move(Collector)); } diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index e489282281d26..5d4248819f1fb 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -397,7 +397,8 @@ void RealFileSystem::printImpl(raw_ostream &OS, PrintType Type, } IntrusiveRefCntPtr<FileSystem> vfs::getRealFileSystem() { - static IntrusiveRefCntPtr<FileSystem> FS(new RealFileSystem(true)); + static IntrusiveRefCntPtr<FileSystem> FS = + makeIntrusiveRefCnt<RealFileSystem>(true); return FS; } @@ -2217,9 +2218,9 @@ RedirectingFileSystem::create(std::unique_ptr<MemoryBuffer> Buffer, std::unique_ptr<RedirectingFileSystem> RedirectingFileSystem::create( ArrayRef<std::pair<std::string, std::string>> RemappedFiles, - bool UseExternalNames, FileSystem &ExternalFS) { + bool UseExternalNames, llvm::IntrusiveRefCntPtr<FileSystem> ExternalFS) { std::unique_ptr<RedirectingFileSystem> FS( - new RedirectingFileSystem(&ExternalFS)); + new RedirectingFileSystem(ExternalFS)); FS->UseExternalNames = UseExternalNames; StringMap<RedirectingFileSystem::Entry *> Entries; @@ -2228,7 +2229,7 @@ std::unique_ptr<RedirectingFileSystem> RedirectingFileSystem::create( SmallString<128> From = StringRef(Mapping.first); SmallString<128> To = StringRef(Mapping.second); { - auto EC = ExternalFS.makeAbsolute(From); + auto EC = ExternalFS->makeAbsolute(From); (void)EC; assert(!EC && "Could not make absolute path"); } @@ -2250,7 +2251,7 @@ std::unique_ptr<RedirectingFileSystem> RedirectingFileSystem::create( } assert(Parent && "File without a directory?"); { - auto EC = ExternalFS.makeAbsolute(To); + auto EC = ExternalFS->makeAbsolute(To); (void)EC; assert(!EC && "Could not make absolute path"); } diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index eb590e474c2ec..fc3ccea1e6463 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -225,7 +225,7 @@ std::string getPosixPath(const Twine &S) { } // end anonymous namespace TEST(VirtualFileSystemTest, StatusQueries) { - IntrusiveRefCntPtr<DummyFileSystem> D(new DummyFileSystem()); + auto D = makeIntrusiveRefCnt<DummyFileSystem>(); ErrorOr<vfs::Status> Status((std::error_code())); D->addRegularFile("/foo"); @@ -265,11 +265,11 @@ TEST(VirtualFileSystemTest, StatusQueries) { } TEST(VirtualFileSystemTest, BaseOnlyOverlay) { - IntrusiveRefCntPtr<DummyFileSystem> D(new DummyFileSystem()); + auto D = makeIntrusiveRefCnt<DummyFileSystem>(); ErrorOr<vfs::Status> Status((std::error_code())); EXPECT_FALSE(Status = D->status("/foo")); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(new vfs::OverlayFileSystem(D)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(D); EXPECT_FALSE(Status = O->status("/foo")); D->addRegularFile("/foo"); @@ -283,13 +283,12 @@ TEST(VirtualFileSystemTest, BaseOnlyOverlay) { } TEST(VirtualFileSystemTest, GetRealPathInOverlay) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addRegularFile("/foo"); Lower->addSymlink("/lower_link"); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Upper); // Regular file. @@ -312,11 +311,10 @@ TEST(VirtualFileSystemTest, GetRealPathInOverlay) { } TEST(VirtualFileSystemTest, OverlayFiles) { - IntrusiveRefCntPtr<DummyFileSystem> Base(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Top(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Base)); + auto Base = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Middle = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Top = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Base); O->pushOverlay(Middle); O->pushOverlay(Top); @@ -351,10 +349,9 @@ TEST(VirtualFileSystemTest, OverlayFiles) { } TEST(VirtualFileSystemTest, OverlayDirsNonMerged) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Upper); Lower->addDirectory("/lower-only"); @@ -376,10 +373,9 @@ TEST(VirtualFileSystemTest, OverlayDirsNonMerged) { TEST(VirtualFileSystemTest, MergedDirPermissions) { // merged directories get the permissions of the upper dir - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Upper); ErrorOr<vfs::Status> Status((std::error_code())); @@ -401,12 +397,11 @@ TEST(VirtualFileSystemTest, MergedDirPermissions) { } TEST(VirtualFileSystemTest, OverlayIterator) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addRegularFile("/foo"); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Upper); ErrorOr<vfs::Status> Status((std::error_code())); @@ -784,10 +779,9 @@ static void checkContents(DirIter I, ArrayRef<StringRef> ExpectedOut) { } TEST(VirtualFileSystemTest, OverlayIteration) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Upper); std::error_code EC; @@ -808,11 +802,10 @@ TEST(VirtualFileSystemTest, OverlayIteration) { } TEST(VirtualFileSystemTest, OverlayRecursiveIteration) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Middle = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Middle); O->pushOverlay(Upper); @@ -850,11 +843,10 @@ TEST(VirtualFileSystemTest, OverlayRecursiveIteration) { } TEST(VirtualFileSystemTest, ThreeLevelIteration) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Middle = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Middle); O->pushOverlay(Upper); @@ -870,11 +862,10 @@ TEST(VirtualFileSystemTest, ThreeLevelIteration) { } TEST(VirtualFileSystemTest, HiddenInIteration) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Middle = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Upper = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Middle); O->pushOverlay(Upper); @@ -913,11 +904,10 @@ TEST(VirtualFileSystemTest, HiddenInIteration) { } TEST(VirtualFileSystemTest, Visit) { - IntrusiveRefCntPtr<DummyFileSystem> Base(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Top(new DummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Base)); + auto Base = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Middle = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Top = makeIntrusiveRefCnt<DummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Base); O->pushOverlay(Middle); O->pushOverlay(Top); @@ -984,10 +974,9 @@ TEST(OverlayFileSystemTest, PrintOutput) { } TEST(OverlayFileSystemTest, Exists) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new NoStatusDummyFileSystem()); - IntrusiveRefCntPtr<DummyFileSystem> Upper(new NoStatusDummyFileSystem()); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto Lower = makeIntrusiveRefCnt<NoStatusDummyFileSystem>(); + auto Upper = makeIntrusiveRefCnt<NoStatusDummyFileSystem>(); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(Upper); Lower->addDirectory("/both"); @@ -1008,8 +997,7 @@ TEST(OverlayFileSystemTest, Exists) { } TEST(ProxyFileSystemTest, Basic) { - IntrusiveRefCntPtr<vfs::InMemoryFileSystem> Base( - new vfs::InMemoryFileSystem()); + auto Base = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); vfs::ProxyFileSystem PFS(Base); Base->addFile("/a", 0, MemoryBuffer::getMemBuffer("test")); @@ -1606,7 +1594,7 @@ TEST_F(VFSFromYAMLTest, BasicVFSFromYAML) { } TEST_F(VFSFromYAMLTest, MappedFiles) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/foo/bar"); Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( @@ -1642,8 +1630,7 @@ TEST_F(VFSFromYAMLTest, MappedFiles) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); // file @@ -1720,7 +1707,7 @@ TEST_F(VFSFromYAMLTest, MappedFiles) { } TEST_F(VFSFromYAMLTest, MappedRoot) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/foo/bar"); Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr<vfs::FileSystem> FS = @@ -1735,8 +1722,7 @@ TEST_F(VFSFromYAMLTest, MappedRoot) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); // file @@ -1762,7 +1748,7 @@ TEST_F(VFSFromYAMLTest, MappedRoot) { } TEST_F(VFSFromYAMLTest, RemappedDirectoryOverlay) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); Lower->addDirectory("//root/bar"); @@ -1783,8 +1769,7 @@ TEST_F(VFSFromYAMLTest, RemappedDirectoryOverlay) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); ErrorOr<vfs::Status> S = O->status("//root/foo"); @@ -1806,7 +1791,7 @@ TEST_F(VFSFromYAMLTest, RemappedDirectoryOverlay) { } TEST_F(VFSFromYAMLTest, RemappedDirectoryOverlayNoExternalNames) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); Lower->addDirectory("//root/bar"); @@ -1847,7 +1832,7 @@ TEST_F(VFSFromYAMLTest, RemappedDirectoryOverlayNoExternalNames) { } TEST_F(VFSFromYAMLTest, RemappedDirectoryOverlayNoFallthrough) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); Lower->addDirectory("//root/bar"); @@ -1887,13 +1872,12 @@ TEST_F(VFSFromYAMLTest, RemappedDirectoryOverlayNoFallthrough) { } TEST_F(VFSFromYAMLTest, ReturnsRequestedPathVFSMiss) { - IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS( - new vfs::InMemoryFileSystem); + auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); BaseFS->addFile("//root/foo/a", 0, MemoryBuffer::getMemBuffer("contents of a")); ASSERT_FALSE(BaseFS->setCurrentWorkingDirectory("//root/foo")); auto RemappedFS = vfs::RedirectingFileSystem::create( - {}, /*UseExternalNames=*/false, *BaseFS); + {}, /*UseExternalNames=*/false, BaseFS); auto OpenedF = RemappedFS->openFileForRead("a"); ASSERT_FALSE(OpenedF.getError()); @@ -1915,8 +1899,7 @@ TEST_F(VFSFromYAMLTest, ReturnsRequestedPathVFSMiss) { } TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) { - IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS( - new vfs::InMemoryFileSystem); + auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); BaseFS->addFile("//root/foo/realname", 0, MemoryBuffer::getMemBuffer("contents of a")); auto FS = @@ -1955,7 +1938,7 @@ TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) { } TEST_F(VFSFromYAMLTest, RootRelativeTest) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/foo/bar"); Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr<vfs::FileSystem> FS = @@ -1996,7 +1979,7 @@ TEST_F(VFSFromYAMLTest, RootRelativeTest) { ASSERT_FALSE(S.getError()); EXPECT_EQ("//root/foo/bar/a", S->getName()); #else - IntrusiveRefCntPtr<DummyFileSystem> LowerWindows(new DummyFileSystem()); + auto LowerWindows = makeIntrusiveRefCnt<DummyFileSystem>(); LowerWindows->addDirectory("\\\\root\\foo\\bar"); LowerWindows->addRegularFile("\\\\root\\foo\\bar\\a"); FS = getFromYAMLString("{\n" @@ -2018,8 +2001,7 @@ TEST_F(VFSFromYAMLTest, RootRelativeTest) { } TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) { - IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS( - new vfs::InMemoryFileSystem); + auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); BaseFS->addFile("//root/foo/realname", 0, MemoryBuffer::getMemBuffer("contents of a")); auto FS = @@ -2058,7 +2040,7 @@ TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) { } TEST_F(VFSFromYAMLTest, CaseInsensitive) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( "{ 'case-sensitive': 'false',\n" @@ -2076,8 +2058,7 @@ TEST_F(VFSFromYAMLTest, CaseInsensitive) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); ErrorOr<vfs::Status> S = O->status("//root/XX"); @@ -2094,7 +2075,7 @@ TEST_F(VFSFromYAMLTest, CaseInsensitive) { } TEST_F(VFSFromYAMLTest, CaseSensitive) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( "{ 'case-sensitive': 'true',\n" @@ -2112,8 +2093,7 @@ TEST_F(VFSFromYAMLTest, CaseSensitive) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); ErrorOr<vfs::Status> SS = O->status("//root/xx"); @@ -2126,7 +2106,7 @@ TEST_F(VFSFromYAMLTest, CaseSensitive) { } TEST_F(VFSFromYAMLTest, IllegalVFSFile) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); // invalid YAML at top-level IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString("{]", Lower); @@ -2252,7 +2232,7 @@ TEST_F(VFSFromYAMLTest, IllegalVFSFile) { } TEST_F(VFSFromYAMLTest, UseExternalName) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addRegularFile("//root/external/file"); IntrusiveRefCntPtr<vfs::FileSystem> FS = @@ -2304,7 +2284,7 @@ TEST_F(VFSFromYAMLTest, UseExternalName) { } TEST_F(VFSFromYAMLTest, MultiComponentPath) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addRegularFile("//root/other"); // file in roots @@ -2350,7 +2330,7 @@ TEST_F(VFSFromYAMLTest, MultiComponentPath) { } TEST_F(VFSFromYAMLTest, TrailingSlashes) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addRegularFile("//root/other"); // file in roots @@ -2369,7 +2349,7 @@ TEST_F(VFSFromYAMLTest, TrailingSlashes) { } TEST_F(VFSFromYAMLTest, DirectoryIteration) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addDirectory("//root/foo"); Lower->addDirectory("//root/foo/bar"); @@ -2399,8 +2379,7 @@ TEST_F(VFSFromYAMLTest, DirectoryIteration) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); std::error_code EC; @@ -2416,7 +2395,7 @@ TEST_F(VFSFromYAMLTest, DirectoryIterationSameDirMultipleEntries) { if (!supportsSameDirMultipleYAMLEntries()) GTEST_SKIP(); - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/zab"); Lower->addDirectory("//root/baz"); Lower->addRegularFile("//root/zab/a"); @@ -2449,8 +2428,7 @@ TEST_F(VFSFromYAMLTest, DirectoryIterationSameDirMultipleEntries) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); std::error_code EC; @@ -2461,7 +2439,7 @@ TEST_F(VFSFromYAMLTest, DirectoryIterationSameDirMultipleEntries) { TEST_F(VFSFromYAMLTest, RecursiveDirectoryIterationLevel) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/a"); Lower->addDirectory("//root/a/b"); Lower->addDirectory("//root/a/b/c"); @@ -2484,8 +2462,7 @@ TEST_F(VFSFromYAMLTest, RecursiveDirectoryIterationLevel) { Lower); ASSERT_NE(FS.get(), nullptr); - IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( - new vfs::OverlayFileSystem(Lower)); + auto O = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Lower); O->pushOverlay(FS); std::error_code EC; @@ -2503,7 +2480,7 @@ TEST_F(VFSFromYAMLTest, RecursiveDirectoryIterationLevel) { } TEST_F(VFSFromYAMLTest, RelativePaths) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); std::error_code EC; SmallString<128> CWD; EC = llvm::sys::fs::current_path(CWD); @@ -2557,7 +2534,7 @@ TEST_F(VFSFromYAMLTest, RelativePaths) { } TEST_F(VFSFromYAMLTest, NonFallthroughDirectoryIteration) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addRegularFile("//root/a"); Lower->addRegularFile("//root/b"); @@ -2586,7 +2563,7 @@ TEST_F(VFSFromYAMLTest, NonFallthroughDirectoryIteration) { } TEST_F(VFSFromYAMLTest, DirectoryIterationWithDuplicates) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addRegularFile("//root/a"); Lower->addRegularFile("//root/b"); @@ -2614,7 +2591,7 @@ TEST_F(VFSFromYAMLTest, DirectoryIterationWithDuplicates) { } TEST_F(VFSFromYAMLTest, DirectoryIterationErrorInVFSLayer) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); @@ -2643,7 +2620,7 @@ TEST_F(VFSFromYAMLTest, DirectoryIterationErrorInVFSLayer) { } TEST_F(VFSFromYAMLTest, GetRealPath) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//dir/"); Lower->addRegularFile("/foo"); Lower->addSymlink("/link"); @@ -2695,7 +2672,7 @@ TEST_F(VFSFromYAMLTest, GetRealPath) { } TEST_F(VFSFromYAMLTest, WorkingDirectory) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); @@ -2753,7 +2730,7 @@ TEST_F(VFSFromYAMLTest, WorkingDirectory) { } TEST_F(VFSFromYAMLTest, WorkingDirectoryFallthrough) { - IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<DummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); @@ -2835,7 +2812,7 @@ TEST_F(VFSFromYAMLTest, WorkingDirectoryFallthrough) { } TEST_F(VFSFromYAMLTest, WorkingDirectoryFallthroughInvalid) { - IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<ErrorDummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); @@ -2872,7 +2849,7 @@ TEST_F(VFSFromYAMLTest, WorkingDirectoryFallthroughInvalid) { } TEST_F(VFSFromYAMLTest, VirtualWorkingDirectory) { - IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<ErrorDummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addDirectory("//root/foo"); Lower->addRegularFile("//root/foo/a"); @@ -2928,7 +2905,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest) { raw_string_ostream OS(Buffer); VFSWriter.write(OS); - IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<ErrorDummyFileSystem>(); Lower->addDirectory("//root/"); Lower->addDirectory("//root/a"); Lower->addRegularFile("//root/a/b"); @@ -2978,7 +2955,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) { raw_string_ostream OS(Buffer); VFSWriter.write(OS); - IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<ErrorDummyFileSystem>(); IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower); EXPECT_NE(FS.get(), nullptr); } @@ -3010,7 +2987,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) { raw_string_ostream OS(Buffer); VFSWriter.write(OS); - IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<ErrorDummyFileSystem>(); IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower); EXPECT_NE(FS.get(), nullptr); } @@ -3033,7 +3010,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) { // We didn't add a single file - only directories. EXPECT_EQ(Buffer.find("'type': 'file'"), std::string::npos); - IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); + auto Lower = makeIntrusiveRefCnt<ErrorDummyFileSystem>(); Lower->addDirectory("//root/a"); Lower->addDirectory("//root/b"); Lower->addDirectory("//root/c"); @@ -3051,17 +3028,17 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) { } TEST_F(VFSFromYAMLTest, RedirectingWith) { - IntrusiveRefCntPtr<DummyFileSystem> Both(new DummyFileSystem()); + auto Both = makeIntrusiveRefCnt<DummyFileSystem>(); Both->addDirectory("//root/a"); Both->addRegularFile("//root/a/f"); Both->addDirectory("//root/b"); Both->addRegularFile("//root/b/f"); - IntrusiveRefCntPtr<DummyFileSystem> AOnly(new DummyFileSystem()); + auto AOnly = makeIntrusiveRefCnt<DummyFileSystem>(); AOnly->addDirectory("//root/a"); AOnly->addRegularFile("//root/a/f"); - IntrusiveRefCntPtr<DummyFileSystem> BOnly(new DummyFileSystem()); + auto BOnly = makeIntrusiveRefCnt<DummyFileSystem>(); BOnly->addDirectory("//root/b"); BOnly->addRegularFile("//root/b/f"); @@ -3166,8 +3143,7 @@ TEST_F(VFSFromYAMLTest, RedirectingWith) { } TEST(VFSFromRemappedFilesTest, Basic) { - IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS = - new vfs::InMemoryFileSystem; + auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); BaseFS->addFile("//root/b", 0, MemoryBuffer::getMemBuffer("contents of b")); BaseFS->addFile("//root/c", 0, MemoryBuffer::getMemBuffer("contents of c")); @@ -3176,7 +3152,7 @@ TEST(VFSFromRemappedFilesTest, Basic) { {"//root/a/b/c", "//root/c"}, }; auto RemappedFS = vfs::RedirectingFileSystem::create( - RemappedFiles, /*UseExternalNames=*/false, *BaseFS); + RemappedFiles, /*UseExternalNames=*/false, BaseFS); auto StatA = RemappedFS->status("//root/a/a"); auto StatB = RemappedFS->status("//root/a/b/c"); @@ -3194,8 +3170,7 @@ TEST(VFSFromRemappedFilesTest, Basic) { } TEST(VFSFromRemappedFilesTest, UseExternalNames) { - IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS = - new vfs::InMemoryFileSystem; + auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); BaseFS->addFile("//root/b", 0, MemoryBuffer::getMemBuffer("contents of b")); BaseFS->addFile("//root/c", 0, MemoryBuffer::getMemBuffer("contents of c")); @@ -3204,7 +3179,7 @@ TEST(VFSFromRemappedFilesTest, UseExternalNames) { {"//root/a/b/c", "//root/c"}, }; auto RemappedFS = vfs::RedirectingFileSystem::create( - RemappedFiles, /*UseExternalNames=*/true, *BaseFS); + RemappedFiles, /*UseExternalNames=*/true, BaseFS); auto StatA = RemappedFS->status("//root/a/a"); auto StatB = RemappedFS->status("//root/a/b/c"); @@ -3222,8 +3197,7 @@ TEST(VFSFromRemappedFilesTest, UseExternalNames) { } TEST(VFSFromRemappedFilesTest, LastMappingWins) { - IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS = - new vfs::InMemoryFileSystem; + auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); BaseFS->addFile("//root/b", 0, MemoryBuffer::getMemBuffer("contents of b")); BaseFS->addFile("//root/c", 0, MemoryBuffer::getMemBuffer("contents of c")); @@ -3232,9 +3206,9 @@ TEST(VFSFromRemappedFilesTest, LastMappingWins) { {"//root/a", "//root/c"}, }; auto RemappedFSKeepName = vfs::RedirectingFileSystem::create( - RemappedFiles, /*UseExternalNames=*/false, *BaseFS); + RemappedFiles, /*UseExternalNames=*/false, BaseFS); auto RemappedFSExternalName = vfs::RedirectingFileSystem::create( - RemappedFiles, /*UseExternalNames=*/true, *BaseFS); + RemappedFiles, /*UseExternalNames=*/true, BaseFS); auto StatKeepA = RemappedFSKeepName->status("//root/a"); auto StatExternalA = RemappedFSExternalName->status("//root/a"); @@ -3416,7 +3390,7 @@ TEST(RedirectingFileSystemTest, ExternalPaths) { BaseFS->setCurrentWorkingDirectory("/cwd"); auto CheckFS = makeIntrusiveRefCnt<InterceptorFS>(BaseFS); auto FS = vfs::RedirectingFileSystem::create({}, /*UseExternalNames=*/false, - *CheckFS); + CheckFS); FS->status("/a/../b"); FS->openFileForRead("c"); @@ -3442,7 +3416,7 @@ TEST(RedirectingFileSystemTest, ExternalPaths) { } TEST(RedirectingFileSystemTest, Exists) { - IntrusiveRefCntPtr<DummyFileSystem> Dummy(new NoStatusDummyFileSystem()); + auto Dummy = makeIntrusiveRefCnt<NoStatusDummyFileSystem>(); auto YAML = MemoryBuffer::getMemBuffer("{\n" " 'version': 0,\n" @@ -3513,7 +3487,7 @@ TEST(RedirectingFileSystemTest, Exists) { } TEST(RedirectingFileSystemTest, ExistsFallback) { - IntrusiveRefCntPtr<DummyFileSystem> Dummy(new NoStatusDummyFileSystem()); + auto Dummy = makeIntrusiveRefCnt<NoStatusDummyFileSystem>(); auto YAML = MemoryBuffer::getMemBuffer("{\n" " 'version': 0,\n" @@ -3537,7 +3511,7 @@ TEST(RedirectingFileSystemTest, ExistsFallback) { } TEST(RedirectingFileSystemTest, ExistsRedirectOnly) { - IntrusiveRefCntPtr<DummyFileSystem> Dummy(new NoStatusDummyFileSystem()); + auto Dummy = makeIntrusiveRefCnt<NoStatusDummyFileSystem>(); auto YAML = MemoryBuffer::getMemBuffer("{\n" " 'version': 0,\n" _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits