diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 9f3d5f97cdff4..a6b6993b708d0 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -83,6 +83,9 @@ class CompilerInstance : public ModuleLoader { /// The options used in this compiler instance. std::shared_ptr Invocation; + /// The virtual file system instance. + IntrusiveRefCntPtr VFS; + /// The diagnostics engine instance. IntrusiveRefCntPtr Diagnostics; @@ -409,9 +412,31 @@ class CompilerInstance : public ModuleLoader { /// @name Virtual File System /// @{ - llvm::vfs::FileSystem &getVirtualFileSystem() const; - llvm::IntrusiveRefCntPtr - getVirtualFileSystemPtr() const; + bool hasVirtualFileSystem() const { return VFS != nullptr; } + + /// Create a virtual file system instance based on the invocation. + /// + /// @param BaseFS The file system that may be used when configuring the final + /// file system, and act as the underlying file system. Must not + /// be NULL. + /// @param DC If non-NULL, the diagnostic consumer to be used in case + /// configuring the file system emits diagnostics. Note that the + /// DiagnosticsEngine using the consumer won't obey the + /// --warning-suppression-mappings= flag. + void createVirtualFileSystem(IntrusiveRefCntPtr + BaseFS = llvm::vfs::getRealFileSystem(), + DiagnosticConsumer *DC = nullptr); + + /// Use the given file system. + void setVirtualFileSystem(IntrusiveRefCntPtr FS) { + VFS = std::move(FS); + } + + llvm::vfs::FileSystem &getVirtualFileSystem() const { return *VFS; } + + IntrusiveRefCntPtr getVirtualFileSystemPtr() const { + return VFS; + } /// @} /// @name File Manager @@ -650,32 +675,31 @@ class CompilerInstance : public ModuleLoader { /// Note that this routine also replaces the diagnostic client, /// allocating one if one is not provided. /// - /// \param VFS is used for any IO needed when creating DiagnosticsEngine. It - /// doesn't replace VFS in the CompilerInstance (if any). - /// /// \param Client If non-NULL, a diagnostic client that will be /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST /// unit. /// /// \param ShouldOwnClient If Client is non-NULL, specifies whether /// the diagnostic object should take ownership of the client. - void createDiagnostics(llvm::vfs::FileSystem &VFS, - DiagnosticConsumer *Client = nullptr, + void createDiagnostics(DiagnosticConsumer *Client = nullptr, bool ShouldOwnClient = true); - /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter. + /// Create a DiagnosticsEngine object. /// /// If no diagnostic client is provided, this creates a /// DiagnosticConsumer that is owned by the returned diagnostic /// object, if using directly the caller is responsible for /// releasing the returned DiagnosticsEngine's client eventually. /// + /// \param VFS The file system used to load the suppression mappings file. + /// /// \param Opts - The diagnostic options; note that the created text /// diagnostic object contains a reference to these options. /// /// \param Client If non-NULL, a diagnostic client that will be /// attached to (and, then, owned by) the returned DiagnosticsEngine - /// object. + /// object. If NULL, the returned DiagnosticsEngine will own a newly-created + /// client. /// /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be /// used by some diagnostics printers (for logging purposes only). @@ -690,8 +714,7 @@ class CompilerInstance : public ModuleLoader { /// Create the file manager and replace any existing one with it. /// /// \return The new file manager on success, or null on failure. - FileManager * - createFileManager(IntrusiveRefCntPtr VFS = nullptr); + FileManager *createFileManager(); /// Create the source manager and replace any existing one with it. void createSourceManager(FileManager &FileMgr); diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 03b08cdabe39e..8b35af152cbc8 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1189,10 +1189,12 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, // 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->setVirtualFileSystem(std::move(VFS)); Clang->setFileManager(FileMgr); - else { - Clang->createFileManager(std::move(VFS)); + } else { + Clang->setVirtualFileSystem(std::move(VFS)); + Clang->createFileManager(); FileMgr = Clang->getFileManagerPtr(); } diff --git a/clang/lib/Frontend/ChainedIncludesSource.cpp b/clang/lib/Frontend/ChainedIncludesSource.cpp index 013814a738a36..82249f893a795 100644 --- a/clang/lib/Frontend/ChainedIncludesSource.cpp +++ b/clang/lib/Frontend/ChainedIncludesSource.cpp @@ -124,6 +124,7 @@ clang::createChainedIncludesSource(CompilerInstance &CI, auto Clang = std::make_unique( std::move(CInvok), CI.getPCHContainerOperations()); + Clang->createVirtualFileSystem(); Clang->setDiagnostics(Diags); Clang->setTarget(TargetInfo::CreateTargetInfo( Clang->getDiagnostics(), Clang->getInvocation().getTargetOpts())); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 31a8d75fec4bd..e8d0bb84c0f45 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -159,17 +159,11 @@ bool CompilerInstance::createTarget() { return true; } -llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const { - return getFileManager().getVirtualFileSystem(); -} - -llvm::IntrusiveRefCntPtr -CompilerInstance::getVirtualFileSystemPtr() const { - return getFileManager().getVirtualFileSystemPtr(); -} - -void CompilerInstance::setFileManager( - llvm::IntrusiveRefCntPtr Value) { +void CompilerInstance::setFileManager(IntrusiveRefCntPtr Value) { + if (!hasVirtualFileSystem()) + setVirtualFileSystem(Value->getVirtualFileSystemPtr()); + assert(Value == nullptr || + getVirtualFileSystemPtr() == Value->getVirtualFileSystemPtr()); FileMgr = std::move(Value); } @@ -289,6 +283,20 @@ static void collectVFSEntries(CompilerInstance &CI, MDC->addFile(E.VPath, E.RPath); } +void CompilerInstance::createVirtualFileSystem( + IntrusiveRefCntPtr BaseFS, DiagnosticConsumer *DC) { + DiagnosticOptions DiagOpts; + DiagnosticsEngine Diags(DiagnosticIDs::create(), DiagOpts, DC, + /*ShouldOwnClient=*/false); + + VFS = createVFSFromCompilerInvocation(getInvocation(), Diags, + std::move(BaseFS)); + // FIXME: Should this go into createVFSFromCompilerInvocation? + if (getFrontendOpts().ShowStats) + VFS = + llvm::makeIntrusiveRefCnt(std::move(VFS)); +} + // Diagnostics static void SetUpDiagnosticLog(DiagnosticOptions &DiagOpts, const CodeGenOptions *CodeGenOpts, @@ -340,11 +348,10 @@ static void SetupSerializedDiagnostics(DiagnosticOptions &DiagOpts, } } -void CompilerInstance::createDiagnostics(llvm::vfs::FileSystem &VFS, - DiagnosticConsumer *Client, +void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client, bool ShouldOwnClient) { - Diagnostics = createDiagnostics(VFS, getDiagnosticOpts(), Client, - ShouldOwnClient, &getCodeGenOpts()); + Diagnostics = createDiagnostics(getVirtualFileSystem(), getDiagnosticOpts(), + Client, ShouldOwnClient, &getCodeGenOpts()); } IntrusiveRefCntPtr CompilerInstance::createDiagnostics( @@ -382,18 +389,9 @@ IntrusiveRefCntPtr CompilerInstance::createDiagnostics( // File Manager -FileManager *CompilerInstance::createFileManager( - IntrusiveRefCntPtr VFS) { - if (!VFS) - VFS = FileMgr ? FileMgr->getVirtualFileSystemPtr() - : createVFSFromCompilerInvocation(getInvocation(), - getDiagnostics()); - assert(VFS && "FileManager has no VFS?"); - if (getFrontendOpts().ShowStats) - VFS = - llvm::makeIntrusiveRefCnt(std::move(VFS)); - FileMgr = llvm::makeIntrusiveRefCnt(getFileSystemOpts(), - std::move(VFS)); +FileManager *CompilerInstance::createFileManager() { + assert(VFS && "CompilerInstance needs a VFS for creating FileManager"); + FileMgr = llvm::makeIntrusiveRefCnt(getFileSystemOpts(), VFS); return FileMgr.get(); } @@ -1174,20 +1172,21 @@ std::unique_ptr CompilerInstance::cloneForModuleCompileImpl( auto &Inv = Instance.getInvocation(); if (ThreadSafeConfig) { - Instance.createFileManager(ThreadSafeConfig->getVFS()); + Instance.setVirtualFileSystem(ThreadSafeConfig->getVFS()); + Instance.createFileManager(); } else if (FrontendOpts.ModulesShareFileManager) { + Instance.setVirtualFileSystem(getVirtualFileSystemPtr()); Instance.setFileManager(getFileManagerPtr()); } else { - Instance.createFileManager(getVirtualFileSystemPtr()); + Instance.setVirtualFileSystem(getVirtualFileSystemPtr()); + Instance.createFileManager(); } if (ThreadSafeConfig) { - Instance.createDiagnostics(Instance.getVirtualFileSystem(), - &ThreadSafeConfig->getDiagConsumer(), + Instance.createDiagnostics(&ThreadSafeConfig->getDiagConsumer(), /*ShouldOwnClient=*/false); } else { Instance.createDiagnostics( - Instance.getVirtualFileSystem(), new ForwardingDiagnosticConsumer(getDiagnosticClient()), /*ShouldOwnClient=*/true); } diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 6b1fcac75ac2b..ca37e0661476d 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -876,6 +876,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, // Set the shared objects, these are reset when we finish processing the // file, otherwise the CompilerInstance will happily destroy them. + CI.setVirtualFileSystem(AST->getFileManager().getVirtualFileSystemPtr()); CI.setFileManager(AST->getFileManagerPtr()); CI.createSourceManager(CI.getFileManager()); CI.getSourceManager().initializeForReplay(AST->getSourceManager()); @@ -966,7 +967,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, return true; } - // Set up the file and source managers, if needed. + // Set up the file system, file and source managers, if needed. + if (!CI.hasVirtualFileSystem()) + CI.createVirtualFileSystem(); if (!CI.hasFileManager()) { if (!CI.createFileManager()) { return false; diff --git a/clang/lib/Frontend/Rewrite/FrontendActions.cpp b/clang/lib/Frontend/Rewrite/FrontendActions.cpp index 6c9c9d5b5c8d3..f5656b3b190e9 100644 --- a/clang/lib/Frontend/Rewrite/FrontendActions.cpp +++ b/clang/lib/Frontend/Rewrite/FrontendActions.cpp @@ -245,8 +245,8 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener { CompilerInstance Instance( std::make_shared(CI.getInvocation()), CI.getPCHContainerOperations(), &CI.getModuleCache()); + Instance.setVirtualFileSystem(CI.getVirtualFileSystemPtr()); Instance.createDiagnostics( - CI.getVirtualFileSystem(), new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()), /*ShouldOwnClient=*/true); Instance.getFrontendOpts().DisableFree = false; diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 84f1c363b5f6f..efb665c95ae7a 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -107,8 +107,10 @@ CreateCI(const llvm::opt::ArgStringList &Argv) { Clang->getHeaderSearchOpts().ResourceDir = CompilerInvocation::GetResourcesPath(Argv[0], nullptr); + Clang->createVirtualFileSystem(); + // Create the actual diagnostics engine. - Clang->createDiagnostics(*llvm::vfs::getRealFileSystem()); + Clang->createDiagnostics(); if (!Clang->hasDiagnostics()) return llvm::createStringError(llvm::errc::not_supported, "Initialization failed. " @@ -474,7 +476,8 @@ Interpreter::createWithCUDA(std::unique_ptr CI, std::make_unique( llvm::vfs::getRealFileSystem()); OverlayVFS->pushOverlay(IMVFS); - CI->createFileManager(OverlayVFS); + CI->createVirtualFileSystem(OverlayVFS); + CI->createFileManager(); llvm::Expected> InterpOrErr = Interpreter::create(std::move(CI)); diff --git a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp index 975c72af0b031..be74ff2cd4799 100644 --- a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp +++ b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp @@ -84,8 +84,8 @@ void ModelInjector::onBodySynthesis(const NamedDecl *D) { // behavior for models CompilerInstance Instance(std::move(Invocation), CI.getPCHContainerOperations()); + Instance.setVirtualFileSystem(CI.getVirtualFileSystemPtr()); Instance.createDiagnostics( - CI.getVirtualFileSystem(), new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()), /*ShouldOwnClient=*/true); diff --git a/clang/lib/Testing/TestAST.cpp b/clang/lib/Testing/TestAST.cpp index b59a8d55129de..9ad0de95530fb 100644 --- a/clang/lib/Testing/TestAST.cpp +++ b/clang/lib/Testing/TestAST.cpp @@ -54,8 +54,10 @@ class StoreDiagnostics : public DiagnosticConsumer { // Fills in the bits of a CompilerInstance that weren't initialized yet. // Provides "empty" ASTContext etc if we fail before parsing gets started. void createMissingComponents(CompilerInstance &Clang) { + if (!Clang.hasVirtualFileSystem()) + Clang.createVirtualFileSystem(); if (!Clang.hasDiagnostics()) - Clang.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Clang.createDiagnostics(); if (!Clang.hasFileManager()) Clang.createFileManager(); if (!Clang.hasSourceManager()) @@ -98,7 +100,9 @@ TestAST::TestAST(const TestInputs &In) { // Extra error conditions are reported through diagnostics, set that up first. bool ErrorOK = In.ErrorOK || llvm::StringRef(In.Code).contains("error-ok"); - Clang->createDiagnostics(*VFS, new StoreDiagnostics(Diagnostics, !ErrorOK)); + auto DiagConsumer = new StoreDiagnostics(Diagnostics, !ErrorOK); + Clang->createVirtualFileSystem(std::move(VFS), DiagConsumer); + Clang->createDiagnostics(DiagConsumer); // Parse cc1 argv, (typically [-std=c++20 input.cc]) into CompilerInvocation. std::vector Argv; @@ -115,7 +119,7 @@ TestAST::TestAST(const TestInputs &In) { } assert(!Clang->getInvocation().getFrontendOpts().DisableFree); - Clang->createFileManager(VFS); + Clang->createFileManager(); // Running the FrontendAction creates the other components: SourceManager, // Preprocessor, ASTContext, Sema. Preprocessor needs TargetInfo to be set. diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index 0855e6dec6158..0a12c479bf8e3 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -414,11 +414,12 @@ class DependencyScanningAction { CompilerInstance &ScanInstance = *ScanInstanceStorage; ScanInstance.setBuildingModule(false); + ScanInstance.createVirtualFileSystem(FS, DiagConsumer); + // Create the compiler's actual diagnostics engine. sanitizeDiagOpts(ScanInstance.getDiagnosticOpts()); assert(!DiagConsumerFinished && "attempt to reuse finished consumer"); - ScanInstance.createDiagnostics(*FS, DiagConsumer, - /*ShouldOwnClient=*/false); + ScanInstance.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false); if (!ScanInstance.hasDiagnostics()) return false; @@ -439,13 +440,8 @@ class DependencyScanningAction { ScanInstance.getHeaderSearchOpts().ModulesIncludeVFSUsage = any(Service.getOptimizeArgs() & ScanningOptimizations::VFS); - // Support for virtual file system overlays. - FS = createVFSFromCompilerInvocation(ScanInstance.getInvocation(), - ScanInstance.getDiagnostics(), - std::move(FS)); - // Create a new FileManager to match the invocation's FileSystemOptions. - auto *FileMgr = ScanInstance.createFileManager(FS); + auto *FileMgr = ScanInstance.createFileManager(); // Use the dependency scanning optimized file system if requested to do so. if (DepFS) { diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp index 0c179b852813d..2d4790b205b1a 100644 --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -454,8 +454,7 @@ bool FrontendActionFactory::runInvocation( std::unique_ptr ScopedToolAction(create()); // Create the compiler's actual diagnostics engine. - Compiler.createDiagnostics(Files->getVirtualFileSystem(), DiagConsumer, - /*ShouldOwnClient=*/false); + Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false); if (!Compiler.hasDiagnostics()) return false; diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index ab021a51bf295..910e08ca4dffa 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -207,8 +207,8 @@ std::unique_ptr BuildCompilerInstance() { auto Ins = std::make_unique(std::move(Inv)); - Ins->createDiagnostics(*llvm::vfs::getRealFileSystem(), DC.release(), - /*ShouldOwnClient=*/true); + Ins->createVirtualFileSystem(llvm::vfs::getRealFileSystem(), DC.get()); + Ins->createDiagnostics(DC.release(), /*ShouldOwnClient=*/true); TargetInfo *TI = TargetInfo::CreateTargetInfo( Ins->getDiagnostics(), Ins->getInvocation().getTargetOpts()); diff --git a/clang/tools/clang-installapi/ClangInstallAPI.cpp b/clang/tools/clang-installapi/ClangInstallAPI.cpp index 049b0bd8f8dbf..16abeb10284c0 100644 --- a/clang/tools/clang-installapi/ClangInstallAPI.cpp +++ b/clang/tools/clang-installapi/ClangInstallAPI.cpp @@ -115,7 +115,7 @@ static bool run(ArrayRef Args, const char *ProgName) { // Set up compilation. std::unique_ptr CI(new CompilerInstance()); CI->setFileManager(FM); - CI->createDiagnostics(FM->getVirtualFileSystem()); + CI->createDiagnostics(); if (!CI->hasDiagnostics()) return EXIT_FAILURE; diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 854ab3e33555b..49f8843515a35 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -271,8 +271,11 @@ int cc1_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { Clang->getHeaderSearchOpts().ResourceDir = CompilerInvocation::GetResourcesPath(Argv0, MainAddr); + /// Create the actual file system. + Clang->createVirtualFileSystem(llvm::vfs::getRealFileSystem(), DiagsBuffer); + // Create the actual diagnostics engine. - Clang->createDiagnostics(*llvm::vfs::getRealFileSystem()); + Clang->createDiagnostics(); if (!Clang->hasDiagnostics()) return 1; @@ -319,8 +322,7 @@ int cc1_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { // options are stored in the compiler invocation and we can recreate the VFS // from the compiler invocation. if (!Clang->hasFileManager()) - Clang->createFileManager(createVFSFromCompilerInvocation( - Clang->getInvocation(), Clang->getDiagnostics())); + Clang->createFileManager(); if (auto profilerOutput = Clang->createOutputFile( Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false, diff --git a/clang/unittests/AST/ExternalASTSourceTest.cpp b/clang/unittests/AST/ExternalASTSourceTest.cpp index 21d4ce4dcf212..15483ad250976 100644 --- a/clang/unittests/AST/ExternalASTSourceTest.cpp +++ b/clang/unittests/AST/ExternalASTSourceTest.cpp @@ -59,7 +59,8 @@ bool testExternalASTSource(llvm::IntrusiveRefCntPtr Source, CompilerInvocation::CreateFromArgs(*Invocation, Args, *InvocationDiags); CompilerInstance Compiler(std::move(Invocation)); - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(); TestFrontendAction Action(Source); return Compiler.ExecuteAction(Action); diff --git a/clang/unittests/CodeGen/TestCompiler.h b/clang/unittests/CodeGen/TestCompiler.h index f6fada5f8a1f0..57b5b079a2e30 100644 --- a/clang/unittests/CodeGen/TestCompiler.h +++ b/clang/unittests/CodeGen/TestCompiler.h @@ -36,7 +36,8 @@ struct TestCompiler { clang::CodeGenOptions CGO = clang::CodeGenOptions()) { compiler.getLangOpts() = LO; compiler.getCodeGenOpts() = CGO; - compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + compiler.createDiagnostics(); std::string TrStr = llvm::Triple::normalize(llvm::sys::getProcessTriple()); llvm::Triple Tr(TrStr); diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp index 4fa27297cfd87..c1c5c9604aa16 100644 --- a/clang/unittests/Driver/ToolChainTest.cpp +++ b/clang/unittests/Driver/ToolChainTest.cpp @@ -579,7 +579,8 @@ TEST(CompilerInvocation, SplitSwarfSingleCrash) { TEST(ToolChainTest, UEFICallingConventionTest) { clang::CompilerInstance compiler; - compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + compiler.createDiagnostics(); std::string TrStr = "x86_64-unknown-uefi"; llvm::Triple Tr(TrStr); diff --git a/clang/unittests/Frontend/CodeGenActionTest.cpp b/clang/unittests/Frontend/CodeGenActionTest.cpp index b2792c44ba5fe..182afdc7ea313 100644 --- a/clang/unittests/Frontend/CodeGenActionTest.cpp +++ b/clang/unittests/Frontend/CodeGenActionTest.cpp @@ -52,7 +52,8 @@ TEST(CodeGenTest, TestNullCodeGen) { Invocation->getFrontendOpts().ProgramAction = EmitLLVM; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler(std::move(Invocation)); - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(); EXPECT_TRUE(Compiler.hasDiagnostics()); std::unique_ptr Act(new NullCodeGenAction); @@ -69,7 +70,8 @@ TEST(CodeGenTest, CodeGenFromIRMemBuffer) { Invocation->getFrontendOpts().ProgramAction = frontend::EmitLLVMOnly; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler(std::move(Invocation)); - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(); EXPECT_TRUE(Compiler.hasDiagnostics()); EmitLLVMOnlyAction Action; diff --git a/clang/unittests/Frontend/CompilerInstanceTest.cpp b/clang/unittests/Frontend/CompilerInstanceTest.cpp index 7c1b6539095fa..36cac5a5dd010 100644 --- a/clang/unittests/Frontend/CompilerInstanceTest.cpp +++ b/clang/unittests/Frontend/CompilerInstanceTest.cpp @@ -72,6 +72,7 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) { // in the CompilerInvocation (as we don't explicitly set our own). CompilerInstance Instance(std::move(CInvok)); Instance.setDiagnostics(Diags); + Instance.createVirtualFileSystem(); Instance.createFileManager(); // Check if the virtual file exists which means that our VFS is used by the @@ -135,8 +136,9 @@ TEST(CompilerInstance, MultipleInputsCleansFileIDs) { ASSERT_TRUE(CInvok) << "could not create compiler invocation"; CompilerInstance Instance(std::move(CInvok)); + Instance.setVirtualFileSystem(VFS); Instance.setDiagnostics(Diags); - Instance.createFileManager(VFS); + Instance.createFileManager(); // Run once for `a.cc` and then for `a.h`. This makes sure we get the same // file ID for `b.h` in the second run as `a.h` from first run. diff --git a/clang/unittests/Frontend/FrontendActionTest.cpp b/clang/unittests/Frontend/FrontendActionTest.cpp index 48c0cfd6a185a..c4003182c4b1d 100644 --- a/clang/unittests/Frontend/FrontendActionTest.cpp +++ b/clang/unittests/Frontend/FrontendActionTest.cpp @@ -91,7 +91,8 @@ TEST(ASTFrontendAction, Sanity) { invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler(std::move(invocation)); - compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + compiler.createDiagnostics(); TestASTFrontendAction test_action; ASSERT_TRUE(compiler.ExecuteAction(test_action)); @@ -110,7 +111,8 @@ TEST(ASTFrontendAction, IncrementalParsing) { invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler(std::move(invocation)); - compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + compiler.createDiagnostics(); TestASTFrontendAction test_action(/*enableIncrementalProcessing=*/true); ASSERT_TRUE(compiler.ExecuteAction(test_action)); @@ -136,7 +138,8 @@ TEST(ASTFrontendAction, LateTemplateIncrementalParsing) { invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler(std::move(invocation)); - compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + compiler.createDiagnostics(); TestASTFrontendAction test_action(/*enableIncrementalProcessing=*/true, /*actOnEndOfTranslationUnit=*/true); @@ -181,7 +184,8 @@ TEST(PreprocessorFrontendAction, EndSourceFile) { Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler(std::move(Invocation)); - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(); TestPPCallbacks *Callbacks = new TestPPCallbacks; TestPPCallbacksFrontendAction TestAction(Callbacks); @@ -242,8 +246,8 @@ TEST(ASTFrontendAction, ExternalSemaSource) { Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler(std::move(Invocation)); auto *TDC = new TypoDiagnosticConsumer; - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem(), TDC, - /*ShouldOwnClient=*/true); + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(TDC, /*ShouldOwnClient=*/true); Compiler.setExternalSemaSource( llvm::makeIntrusiveRefCnt(Compiler)); @@ -275,7 +279,8 @@ TEST(GeneratePCHFrontendAction, CacheGeneratedPCH) { Invocation->getFrontendOpts().ProgramAction = frontend::GeneratePCH; Invocation->getTargetOpts().Triple = "x86_64-apple-darwin19.0.0"; CompilerInstance Compiler(std::move(Invocation)); - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(); GeneratePCHAction TestAction; ASSERT_TRUE(Compiler.ExecuteAction(TestAction)); diff --git a/clang/unittests/Frontend/OutputStreamTest.cpp b/clang/unittests/Frontend/OutputStreamTest.cpp index dfb5a544cb88a..9e288f86351ca 100644 --- a/clang/unittests/Frontend/OutputStreamTest.cpp +++ b/clang/unittests/Frontend/OutputStreamTest.cpp @@ -38,7 +38,8 @@ TEST(FrontendOutputTests, TestOutputStream) { new raw_svector_ostream(IRBuffer)); Compiler.setOutputStream(std::move(IRStream)); - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(); bool Success = ExecuteCompilerInvocation(&Compiler); EXPECT_TRUE(Success); @@ -62,8 +63,8 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamShared) { Compiler.setOutputStream(std::make_unique()); DiagnosticOptions DiagOpts; - Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem(), - new TextDiagnosticPrinter(llvm::nulls(), DiagOpts), + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); + Compiler.createDiagnostics(new TextDiagnosticPrinter(llvm::nulls(), DiagOpts), true); Compiler.setVerboseOutputStream(VerboseStream); @@ -92,8 +93,8 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) { Compiler.setOutputStream(std::make_unique()); DiagnosticOptions DiagOpts; + Compiler.setVirtualFileSystem(llvm::vfs::getRealFileSystem()); Compiler.createDiagnostics( - *llvm::vfs::getRealFileSystem(), new TextDiagnosticPrinter(llvm::nulls(), DiagOpts), true); Compiler.setVerboseOutputStream(std::move(VerboseStream)); diff --git a/clang/unittests/Serialization/ForceCheckFileInputTest.cpp b/clang/unittests/Serialization/ForceCheckFileInputTest.cpp index 92ff76b016283..24e2fd65f3c0a 100644 --- a/clang/unittests/Serialization/ForceCheckFileInputTest.cpp +++ b/clang/unittests/Serialization/ForceCheckFileInputTest.cpp @@ -91,10 +91,8 @@ export int aa = 43; Instance.getFrontendOpts().OutputFile = BMIPath; - if (auto VFSWithRemapping = createVFSFromCompilerInvocation( - Instance.getInvocation(), Instance.getDiagnostics(), CIOpts.VFS)) - CIOpts.VFS = VFSWithRemapping; - Instance.createFileManager(CIOpts.VFS); + Instance.createVirtualFileSystem(CIOpts.VFS); + Instance.createFileManager(); Instance.getHeaderSearchOpts().ValidateASTInputFilesContent = true; @@ -123,7 +121,8 @@ export int aa = 43; CompilerInstance Clang(std::move(Invocation)); Clang.setDiagnostics(Diags); - FileManager *FM = Clang.createFileManager(CIOpts.VFS); + Clang.createVirtualFileSystem(CIOpts.VFS); + FileManager *FM = Clang.createFileManager(); Clang.createSourceManager(*FM); EXPECT_TRUE(Clang.createTarget()); diff --git a/clang/unittests/Serialization/ModuleCacheTest.cpp b/clang/unittests/Serialization/ModuleCacheTest.cpp index 1f64401a08314..e9b8da3dba6af 100644 --- a/clang/unittests/Serialization/ModuleCacheTest.cpp +++ b/clang/unittests/Serialization/ModuleCacheTest.cpp @@ -121,6 +121,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) { createInvocationAndEnableFree(Args, CIOpts); ASSERT_TRUE(Invocation); CompilerInstance Instance(std::move(Invocation)); + Instance.setVirtualFileSystem(CIOpts.VFS); Instance.setDiagnostics(Diags); SyntaxOnlyAction Action; ASSERT_TRUE(Instance.ExecuteAction(Action)); @@ -145,6 +146,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) { CompilerInstance Instance2(std::move(Invocation2), Instance.getPCHContainerOperations(), &Instance.getModuleCache()); + Instance2.setVirtualFileSystem(CIOpts.VFS); Instance2.setDiagnostics(Diags); SyntaxOnlyAction Action2; ASSERT_FALSE(Instance2.ExecuteAction(Action2)); @@ -171,6 +173,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) { createInvocationAndEnableFree(Args, CIOpts); ASSERT_TRUE(Invocation); CompilerInstance Instance(std::move(Invocation)); + Instance.setVirtualFileSystem(CIOpts.VFS); Instance.setDiagnostics(Diags); SyntaxOnlyAction Action; ASSERT_TRUE(Instance.ExecuteAction(Action)); @@ -189,6 +192,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) { CompilerInstance Instance2(std::move(Invocation2), Instance.getPCHContainerOperations(), &Instance.getModuleCache()); + Instance2.setVirtualFileSystem(CIOpts.VFS); Instance2.setDiagnostics(Diags); SyntaxOnlyAction Action2; ASSERT_FALSE(Instance2.ExecuteAction(Action2)); diff --git a/clang/unittests/Serialization/NoCommentsTest.cpp b/clang/unittests/Serialization/NoCommentsTest.cpp index ed96c7c7959a0..01bb6999a7c90 100644 --- a/clang/unittests/Serialization/NoCommentsTest.cpp +++ b/clang/unittests/Serialization/NoCommentsTest.cpp @@ -99,6 +99,7 @@ void foo() {} ASSERT_TRUE(Invocation); CompilerInstance Instance(std::move(Invocation)); + Instance.createVirtualFileSystem(CIOpts.VFS); Instance.setDiagnostics(Diags); Instance.getFrontendOpts().OutputFile = CacheBMIPath; GenerateReducedModuleInterfaceAction Action; diff --git a/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp b/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp index f9d7736a77ee1..55ee72875ead2 100644 --- a/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp +++ b/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp @@ -113,12 +113,8 @@ export using ::E; auto Clang = std::make_unique(std::move(Invocation)); Clang->setDiagnostics(Diags); - - if (auto VFSWithRemapping = createVFSFromCompilerInvocation( - Clang->getInvocation(), Clang->getDiagnostics(), VFS)) - VFS = VFSWithRemapping; - - Clang->createFileManager(VFS); + Clang->createVirtualFileSystem(VFS); + Clang->createFileManager(); EXPECT_TRUE(Clang->createTarget()); Buffer.release(); diff --git a/clang/unittests/Support/TimeProfilerTest.cpp b/clang/unittests/Support/TimeProfilerTest.cpp index 871c59f650c82..e544c892635e8 100644 --- a/clang/unittests/Support/TimeProfilerTest.cpp +++ b/clang/unittests/Support/TimeProfilerTest.cpp @@ -52,7 +52,6 @@ bool compileFromString(StringRef Code, StringRef Standard, StringRef File, FS->addFile(Header.getKey(), 0, MemoryBuffer::getMemBuffer(Header.getValue())); } - auto Files = llvm::makeIntrusiveRefCnt(FileSystemOptions(), FS); auto Invocation = std::make_shared(); std::vector Args = {Standard.data(), File.data()}; @@ -62,8 +61,9 @@ bool compileFromString(StringRef Code, StringRef Standard, StringRef File, CompilerInvocation::CreateFromArgs(*Invocation, Args, *InvocationDiags); CompilerInstance Compiler(std::move(Invocation)); - Compiler.createDiagnostics(Files->getVirtualFileSystem()); - Compiler.setFileManager(Files); + Compiler.setVirtualFileSystem(std::move(FS)); + Compiler.createDiagnostics(); + Compiler.createFileManager(); class TestFrontendAction : public ASTFrontendAction { private: diff --git a/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp index b16dd8e6e2b8f..80289efd374cf 100644 --- a/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp +++ b/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp @@ -61,8 +61,7 @@ class TestDependencyScanningAction : public tooling::ToolAction { std::move(PCHContainerOps)); Compiler.setFileManager(FileMgr); - Compiler.createDiagnostics(FileMgr->getVirtualFileSystem(), DiagConsumer, - /*ShouldOwnClient=*/false); + Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false); if (!Compiler.hasDiagnostics()) return false;