From 6f2a034300a331d3817f74f5e414e4c7f267cfe7 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Fri, 17 Oct 2025 12:34:56 -0700 Subject: [PATCH 1/5] [ClangImporter] Fix build after LLVM #150123 --- lib/ClangImporter/ClangImporter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 43ea6cce93991..bd3adfe1914d8 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1015,7 +1015,8 @@ 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.setFileManager(&Impl.Instance->getFileManager()); + CI.createSourceManager(CI.getFileManager()); auto &clangSrcMgr = CI.getSourceManager(); auto FID = clangSrcMgr.createFileID( std::make_unique(1, "
")); From cd10569380d834ac4ad271091effde90061b469a Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Fri, 17 Oct 2025 15:30:54 -0700 Subject: [PATCH 2/5] [ClangImporter] Fix build after LLVM #158381 --- lib/ClangImporter/ClangImporter.cpp | 54 +++++++++++++---------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index bd3adfe1914d8..324ed82721bed 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1015,6 +1015,7 @@ 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.setVirtualFileSystem(Impl.Instance->getVirtualFileSystemPtr()); CI.setFileManager(&Impl.Instance->getFileManager()); CI.createSourceManager(CI.getFileManager()); auto &clangSrcMgr = CI.getSourceManager(); @@ -1395,21 +1396,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 @@ -1428,11 +1423,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; @@ -1917,15 +1914,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->getVirtualFileSystemPtr()); + rewriteInstance.setFileManager(&Impl.Instance->getFileManager()); + rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer); + rewriteInstance.createSourceManager(rewriteInstance.getFileManager()); rewriteInstance.setTarget(&Impl.Instance->getTarget()); std::string result; @@ -1973,7 +1969,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(); } @@ -2022,16 +2019,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->getVirtualFileSystemPtr()); + clonedInstance->setFileManager(&Impl.Instance->getFileManager()); + clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(), /*ShouldOwnClient=*/false); - clonedInstance->setFileManager(&fileManager); - clonedInstance->createSourceManager(fileManager); + clonedInstance->createSourceManager(clonedInstance->getFileManager()); clonedInstance->setTarget(&Impl.Instance->getTarget()); clonedInstance->setOutputBackend(Impl.SwiftContext.OutputBackend); From 87466ba7517eacd2f307bdd607903a66a80ffec2 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Fri, 17 Oct 2025 21:02:12 -0700 Subject: [PATCH 3/5] [ClangImporter] Fix build after LLVM #160188 --- lib/IRGen/IRGen.cpp | 5 ----- 1 file changed, 5 deletions(-) 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, From 651a535480d0e615896858ff5415d826b1f8142a Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Fri, 17 Oct 2025 21:51:05 -0700 Subject: [PATCH 4/5] [ClangImporter] Fix build after LLVM #160748 --- lib/ClangImporter/ClangImporter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 324ed82721bed..eab7c3d65cf42 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1017,7 +1017,7 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) { // reused when building PCM files for the module cache. CI.setVirtualFileSystem(Impl.Instance->getVirtualFileSystemPtr()); CI.setFileManager(&Impl.Instance->getFileManager()); - CI.createSourceManager(CI.getFileManager()); + CI.createSourceManager(); auto &clangSrcMgr = CI.getSourceManager(); auto FID = clangSrcMgr.createFileID( std::make_unique(1, "
")); @@ -1921,7 +1921,7 @@ std::string ClangImporter::getBridgingHeaderContents( Impl.Instance->getVirtualFileSystemPtr()); rewriteInstance.setFileManager(&Impl.Instance->getFileManager()); rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer); - rewriteInstance.createSourceManager(rewriteInstance.getFileManager()); + rewriteInstance.createSourceManager(); rewriteInstance.setTarget(&Impl.Instance->getTarget()); std::string result; @@ -2027,7 +2027,7 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() { clonedInstance->setFileManager(&Impl.Instance->getFileManager()); clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(), /*ShouldOwnClient=*/false); - clonedInstance->createSourceManager(clonedInstance->getFileManager()); + clonedInstance->createSourceManager(); clonedInstance->setTarget(&Impl.Instance->getTarget()); clonedInstance->setOutputBackend(Impl.SwiftContext.OutputBackend); From 7d333819a2bc9d0a90ace4498f4f12304cf33d4f Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Sun, 19 Oct 2025 21:08:40 -0700 Subject: [PATCH 5/5] [ClangImporter] Experimental fix to assertion failure on Windows --- lib/ClangImporter/ClangImporter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index eab7c3d65cf42..fb6df1a2ce585 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1015,7 +1015,8 @@ 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.setVirtualFileSystem(Impl.Instance->getVirtualFileSystemPtr()); + CI.setVirtualFileSystem( + Impl.Instance->getFileManager().getVirtualFileSystemPtr()); CI.setFileManager(&Impl.Instance->getFileManager()); CI.createSourceManager(); auto &clangSrcMgr = CI.getSourceManager(); @@ -1918,7 +1919,7 @@ std::string ClangImporter::getBridgingHeaderContents( std::move(invocation), Impl.Instance->getPCHContainerOperations(), &Impl.Instance->getModuleCache()); rewriteInstance.setVirtualFileSystem( - Impl.Instance->getVirtualFileSystemPtr()); + Impl.Instance->getFileManager().getVirtualFileSystemPtr()); rewriteInstance.setFileManager(&Impl.Instance->getFileManager()); rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer); rewriteInstance.createSourceManager(); @@ -2023,7 +2024,7 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() { std::move(invocation), Impl.Instance->getPCHContainerOperations(), &Impl.Instance->getModuleCache()); clonedInstance->setVirtualFileSystem( - Impl.Instance->getVirtualFileSystemPtr()); + Impl.Instance->getFileManager().getVirtualFileSystemPtr()); clonedInstance->setFileManager(&Impl.Instance->getFileManager()); clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(), /*ShouldOwnClient=*/false);