@@ -1021,10 +1021,7 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
10211021
10221022 // Note: Reusing the file manager is safe; this is a component that's already
10231023 // reused when building PCM files for the module cache.
1024- CI.setVirtualFileSystem (
1025- Impl.Instance ->getFileManager ().getVirtualFileSystemPtr ());
1026- CI.setFileManager (&Impl.Instance ->getFileManager ());
1027- CI.createSourceManager ();
1024+ CI.createSourceManager (Impl.Instance ->getFileManager ());
10281025 auto &clangSrcMgr = CI.getSourceManager ();
10291026 auto FID = clangSrcMgr.createFileID (
10301027 std::make_unique<ZeroFilledMemoryBuffer>(1 , " <main>" ));
@@ -1405,15 +1402,21 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14051402 if (tracker)
14061403 instance.addDependencyCollector (tracker->getClangCollector ());
14071404
1408- // Now set up the real client for Clang diagnostics---configured with proper
1409- // options---as opposed to the temporary one we made above.
1410- auto actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
1411- importer->Impl , instance.getDiagnosticOpts (),
1412- importerOpts.DumpClangDiagnostics );
1405+ {
1406+ // Now set up the real client for Clang diagnostics---configured with proper
1407+ // options---as opposed to the temporary one we made above.
1408+ auto actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
1409+ importer->Impl , instance.getDiagnosticOpts (),
1410+ importerOpts.DumpClangDiagnostics );
1411+ instance.createDiagnostics (*VFS, actualDiagClient.release ());
1412+ }
14131413
1414- instance.createVirtualFileSystem (std::move (VFS), actualDiagClient.get ());
1415- instance.createFileManager ();
1416- instance.createDiagnostics (actualDiagClient.release ());
1414+ // Set up the file manager.
1415+ {
1416+ VFS = clang::createVFSFromCompilerInvocation (
1417+ instance.getInvocation (), instance.getDiagnostics (), std::move (VFS));
1418+ instance.createFileManager (VFS);
1419+ }
14171420
14181421 // Don't stop emitting messages if we ever can't load a module.
14191422 // FIXME: This is actually a general problem: any "fatal" error could mess up
@@ -1432,13 +1435,11 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14321435 if (ctx.LangOpts .ClangTarget .has_value ()) {
14331436 // If '-clang-target' is set, create a mock invocation with the Swift triple
14341437 // to configure CodeGen and Target options for Swift compilation.
1435- auto swiftTargetClangArgs = importer->getClangCC1Arguments (
1436- ctx, instance.getVirtualFileSystemPtr (), true );
1438+ auto swiftTargetClangArgs = importer->getClangCC1Arguments (ctx, VFS, true );
14371439 if (!swiftTargetClangArgs)
14381440 return nullptr ;
14391441 auto swiftTargetClangInvocation = createClangInvocation (
1440- importer.get (), importerOpts, instance.getVirtualFileSystemPtr (),
1441- *swiftTargetClangArgs);
1442+ importer.get (), importerOpts, VFS, *swiftTargetClangArgs);
14421443 if (!swiftTargetClangInvocation)
14431444 return nullptr ;
14441445
@@ -1923,14 +1924,15 @@ std::string ClangImporter::getBridgingHeaderContents(
19231924
19241925 invocation->getPreprocessorOpts ().resetNonModularOptions ();
19251926
1927+ clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
1928+
19261929 clang::CompilerInstance rewriteInstance (
19271930 std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
19281931 &Impl.Instance ->getModuleCache ());
1929- rewriteInstance.setVirtualFileSystem (
1930- Impl.Instance ->getFileManager ().getVirtualFileSystemPtr ());
1931- rewriteInstance.setFileManager (&Impl.Instance ->getFileManager ());
1932- rewriteInstance.createDiagnostics (new clang::IgnoringDiagConsumer);
1933- rewriteInstance.createSourceManager ();
1932+ rewriteInstance.createDiagnostics (fileManager.getVirtualFileSystem (),
1933+ new clang::IgnoringDiagConsumer);
1934+ rewriteInstance.setFileManager (&fileManager);
1935+ rewriteInstance.createSourceManager (fileManager);
19341936 rewriteInstance.setTarget (&Impl.Instance ->getTarget ());
19351937
19361938 std::string result;
@@ -1978,8 +1980,7 @@ std::string ClangImporter::getBridgingHeaderContents(
19781980 return " " ;
19791981 }
19801982
1981- if (auto fileInfo =
1982- rewriteInstance.getFileManager ().getOptionalFileRef (headerPath)) {
1983+ if (auto fileInfo = fileManager.getOptionalFileRef (headerPath)) {
19831984 fileSize = fileInfo->getSize ();
19841985 fileModTime = fileInfo->getModificationTime ();
19851986 }
@@ -2028,15 +2029,16 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
20282029 // Share the CASOption and the underlying CAS.
20292030 invocation->setCASOption (Impl.Invocation ->getCASOptsPtr ());
20302031
2032+ clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
2033+
20312034 auto clonedInstance = std::make_unique<clang::CompilerInstance>(
20322035 std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
20332036 &Impl.Instance ->getModuleCache ());
2034- clonedInstance->setVirtualFileSystem (
2035- Impl.Instance ->getFileManager ().getVirtualFileSystemPtr ());
2036- clonedInstance->setFileManager (&Impl.Instance ->getFileManager ());
2037- clonedInstance->createDiagnostics (&Impl.Instance ->getDiagnosticClient (),
2037+ clonedInstance->createDiagnostics (fileManager.getVirtualFileSystem (),
2038+ &Impl.Instance ->getDiagnosticClient (),
20382039 /* ShouldOwnClient=*/ false );
2039- clonedInstance->createSourceManager ();
2040+ clonedInstance->setFileManager (&fileManager);
2041+ clonedInstance->createSourceManager (fileManager);
20402042 clonedInstance->setTarget (&Impl.Instance ->getTarget ());
20412043 clonedInstance->setOutputBackend (Impl.SwiftContext .OutputBackend );
20422044
0 commit comments