diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 43ea6cce93991..fb6df1a2ce585 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1015,7 +1015,10 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) { // Note: Reusing the file manager is safe; this is a component that's already // reused when building PCM files for the module cache. - CI.createSourceManager(Impl.Instance->getFileManager()); + CI.setVirtualFileSystem( + Impl.Instance->getFileManager().getVirtualFileSystemPtr()); + CI.setFileManager(&Impl.Instance->getFileManager()); + CI.createSourceManager(); auto &clangSrcMgr = CI.getSourceManager(); auto FID = clangSrcMgr.createFileID( std::make_unique(1, "
")); @@ -1394,21 +1397,15 @@ std::unique_ptr ClangImporter::create( if (tracker) instance.addDependencyCollector(tracker->getClangCollector()); - { - // Now set up the real client for Clang diagnostics---configured with proper - // options---as opposed to the temporary one we made above. - auto actualDiagClient = std::make_unique( - importer->Impl, instance.getDiagnosticOpts(), - importerOpts.DumpClangDiagnostics); - instance.createDiagnostics(*VFS, actualDiagClient.release()); - } + // Now set up the real client for Clang diagnostics---configured with proper + // options---as opposed to the temporary one we made above. + auto actualDiagClient = std::make_unique( + importer->Impl, instance.getDiagnosticOpts(), + importerOpts.DumpClangDiagnostics); - // Set up the file manager. - { - VFS = clang::createVFSFromCompilerInvocation( - instance.getInvocation(), instance.getDiagnostics(), std::move(VFS)); - instance.createFileManager(VFS); - } + instance.createVirtualFileSystem(std::move(VFS), actualDiagClient.get()); + instance.createFileManager(); + instance.createDiagnostics(actualDiagClient.release()); // Don't stop emitting messages if we ever can't load a module. // FIXME: This is actually a general problem: any "fatal" error could mess up @@ -1427,11 +1424,13 @@ std::unique_ptr ClangImporter::create( if (ctx.LangOpts.ClangTarget.has_value()) { // If '-clang-target' is set, create a mock invocation with the Swift triple // to configure CodeGen and Target options for Swift compilation. - auto swiftTargetClangArgs = importer->getClangCC1Arguments(ctx, VFS, true); + auto swiftTargetClangArgs = importer->getClangCC1Arguments( + ctx, instance.getVirtualFileSystemPtr(), true); if (!swiftTargetClangArgs) return nullptr; auto swiftTargetClangInvocation = createClangInvocation( - importer.get(), importerOpts, VFS, *swiftTargetClangArgs); + importer.get(), importerOpts, instance.getVirtualFileSystemPtr(), + *swiftTargetClangArgs); if (!swiftTargetClangInvocation) return nullptr; @@ -1916,15 +1915,14 @@ std::string ClangImporter::getBridgingHeaderContents( invocation->getPreprocessorOpts().resetNonModularOptions(); - clang::FileManager &fileManager = Impl.Instance->getFileManager(); - clang::CompilerInstance rewriteInstance( std::move(invocation), Impl.Instance->getPCHContainerOperations(), &Impl.Instance->getModuleCache()); - rewriteInstance.createDiagnostics(fileManager.getVirtualFileSystem(), - new clang::IgnoringDiagConsumer); - rewriteInstance.setFileManager(&fileManager); - rewriteInstance.createSourceManager(fileManager); + rewriteInstance.setVirtualFileSystem( + Impl.Instance->getFileManager().getVirtualFileSystemPtr()); + rewriteInstance.setFileManager(&Impl.Instance->getFileManager()); + rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer); + rewriteInstance.createSourceManager(); rewriteInstance.setTarget(&Impl.Instance->getTarget()); std::string result; @@ -1972,7 +1970,8 @@ std::string ClangImporter::getBridgingHeaderContents( return ""; } - if (auto fileInfo = fileManager.getOptionalFileRef(headerPath)) { + if (auto fileInfo = + rewriteInstance.getFileManager().getOptionalFileRef(headerPath)) { fileSize = fileInfo->getSize(); fileModTime = fileInfo->getModificationTime(); } @@ -2021,16 +2020,15 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() { // Share the CASOption and the underlying CAS. invocation->setCASOption(Impl.Invocation->getCASOptsPtr()); - clang::FileManager &fileManager = Impl.Instance->getFileManager(); - auto clonedInstance = std::make_unique( std::move(invocation), Impl.Instance->getPCHContainerOperations(), &Impl.Instance->getModuleCache()); - clonedInstance->createDiagnostics(fileManager.getVirtualFileSystem(), - &Impl.Instance->getDiagnosticClient(), + clonedInstance->setVirtualFileSystem( + Impl.Instance->getFileManager().getVirtualFileSystemPtr()); + clonedInstance->setFileManager(&Impl.Instance->getFileManager()); + clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(), /*ShouldOwnClient=*/false); - clonedInstance->setFileManager(&fileManager); - clonedInstance->createSourceManager(fileManager); + clonedInstance->createSourceManager(); clonedInstance->setTarget(&Impl.Instance->getTarget()); clonedInstance->setOutputBackend(Impl.SwiftContext.OutputBackend); diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 66b53079a3014..2268f9069e160 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -261,7 +261,6 @@ static std::optional buildIRUseOptions(const IRGenOptions &Opts, /*CSProfileGenFile=*/"", /*ProfileRemappingFile=*/"", /*MemoryProfile=*/"", - /*FS=*/FS, /*Action=*/PGOOptions::IRUse, /*CSPGOAction=*/IsCS ? PGOOptions::CSIRUse : PGOOptions::NoCSAction, /*ColdType=*/PGOOptions::ColdFuncOpt::Default, @@ -277,7 +276,6 @@ static void populatePGOOptions(std::optional &Out, /*CSProfileGenFile=*/ "", /*ProfileRemappingFile=*/ "", /*MemoryProfile=*/ "", - /*FS=*/ llvm::vfs::getRealFileSystem(), // TODO: is this fine? /*Action=*/ PGOOptions::SampleUse, /*CSPGOAction=*/ PGOOptions::NoCSAction, /*ColdType=*/ PGOOptions::ColdFuncOpt::Default, @@ -293,7 +291,6 @@ static void populatePGOOptions(std::optional &Out, /*CSProfileGenFile=*/Opts.InstrProfileOutput, /*ProfileRemappingFile=*/"", /*MemoryProfile=*/"", - /*FS=*/llvm::vfs::getRealFileSystem(), /*Action=*/hasUse ? PGOOptions::IRUse : PGOOptions::NoAction, /*CSPGOAction=*/PGOOptions::CSIRInstr, /*ColdType=*/PGOOptions::ColdFuncOpt::Default, @@ -307,7 +304,6 @@ static void populatePGOOptions(std::optional &Out, /*CSProfileGenFile=*/"", /*ProfileRemappingFile=*/"", /*MemoryProfile=*/"", - /*FS=*/llvm::vfs::getRealFileSystem(), /*Action=*/PGOOptions::IRInstr, /*CSPGOAction=*/PGOOptions::NoCSAction, /*ColdType=*/PGOOptions::ColdFuncOpt::Default, @@ -326,7 +322,6 @@ static void populatePGOOptions(std::optional &Out, /*CSProfileGenFile=*/ "", /*ProfileRemappingFile=*/ "", /*MemoryProfile=*/ "", - /*FS=*/ nullptr, /*Action=*/ PGOOptions::NoAction, /*CSPGOAction=*/ PGOOptions::NoCSAction, /*ColdType=*/ PGOOptions::ColdFuncOpt::Default,