From dcb905bddd4c9a794a7b3b7c0b8cb4c0a40c94d1 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 15:38:12 +0100 Subject: [PATCH 01/14] Basic: Conservatively handle new `llvm::Triple` case Added in https://github.com/llvm/llvm-project/pull/87845 --- lib/Basic/Platform.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp index 107159f9dab37..d6e592d8e995c 100644 --- a/lib/Basic/Platform.cpp +++ b/lib/Basic/Platform.cpp @@ -273,6 +273,7 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) { return "none"; case llvm::Triple::UEFI: case llvm::Triple::LiteOS: + case llvm::Triple::Managarm: llvm_unreachable("unsupported OS"); } llvm_unreachable("unsupported OS"); From 9322c9f9924025e86a9d7724e5f9b25fc96e8c4b Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 15:50:09 +0100 Subject: [PATCH 02/14] Adjust calls to `clang::TargetInfo::CreateTargetInfo` (now takes ref vs. ptr) See https://github.com/llvm/llvm-project/pull/106271 --- lib/Basic/TargetInfo.cpp | 8 ++++---- lib/ClangImporter/ClangImporter.cpp | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 0a80a98d6b0de..111bba9d30d6f 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -148,10 +148,10 @@ void printTripleInfo(const CompilerInvocation &invocation, clang::DiagnosticsEngine DE{new clang::DiagnosticIDs(), new clang::DiagnosticOptions(), new clang::IgnoringDiagConsumer()}; - std::shared_ptr TO = - std::make_shared(); - TO->Triple = triple.str(); - clang::TargetInfo *TI = clang::TargetInfo::CreateTargetInfo(DE, TO); + + clang::TargetOptions targetOpts; + targetOpts.Triple = triple.str(); + clang::TargetInfo *TI = clang::TargetInfo::CreateTargetInfo(DE, targetOpts); out << " \"pointerWidthInBits\": " << TI->getPointerWidth(clang::LangAS::Default) << ",\n"; out << " \"pointerWidthInBytes\": " diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index deca1a9112629..12b5f536ac924 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1414,7 +1414,7 @@ ClangImporter::create(ASTContext &ctx, if (!swiftTargetClangInvocation) return nullptr; auto targetInfo = clang::TargetInfo::CreateTargetInfo( - clangDiags, swiftTargetClangInvocation->TargetOpts); + clangDiags, swiftTargetClangInvocation->getTargetOpts()); // Ensure the target info has configured target-specific defines std::string defineBuffer; llvm::raw_string_ostream predefines(defineBuffer); @@ -1426,7 +1426,7 @@ ClangImporter::create(ASTContext &ctx, } else { // Just use the existing Invocation's directly importer->Impl.setSwiftTargetInfo(clang::TargetInfo::CreateTargetInfo( - clangDiags, importer->Impl.Invocation->TargetOpts)); + clangDiags, importer->Impl.Invocation->getTargetOpts())); importer->Impl.setSwiftCodeGenOptions( new clang::CodeGenOptions(importer->Impl.Invocation->getCodeGenOpts())); } @@ -1445,9 +1445,8 @@ ClangImporter::create(ASTContext &ctx, // things here. // Create the target instance. - instance.setTarget( - clang::TargetInfo::CreateTargetInfo(clangDiags, - instance.getInvocation().TargetOpts)); + instance.setTarget(clang::TargetInfo::CreateTargetInfo( + clangDiags, instance.getInvocation().getTargetOpts())); if (!instance.hasTarget()) return nullptr; From 0981b71090622100019bcd857a62262e2f96bda9 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 15:50:42 +0100 Subject: [PATCH 03/14] Adjust calls to `clang::DiagnosticsEngine` ctor (now takes ref vs. ptr) See https://github.com/llvm/llvm-project/pull/139584 --- lib/Basic/TargetInfo.cpp | 4 ++-- lib/ClangImporter/ClangDiagnosticConsumer.cpp | 15 ++++++------- lib/ClangImporter/ClangImporter.cpp | 21 +++++++++---------- lib/ClangImporter/ClangIncludePaths.cpp | 3 ++- .../ClangModuleDependencyScanner.cpp | 4 ++-- lib/IDETool/CompilerInvocation.cpp | 7 ++----- lib/Migrator/Migrator.cpp | 10 ++++----- 7 files changed, 29 insertions(+), 35 deletions(-) diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 111bba9d30d6f..36e1512d1d103 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -145,8 +145,8 @@ void printTripleInfo(const CompilerInvocation &invocation, out << " \"arch\": \"" << swift::getMajorArchitectureName(triple) << "\",\n"; - clang::DiagnosticsEngine DE{new clang::DiagnosticIDs(), - new clang::DiagnosticOptions(), + clang::DiagnosticOptions diagOpts; + clang::DiagnosticsEngine DE{new clang::DiagnosticIDs(), diagOpts, new clang::IgnoringDiagConsumer()}; clang::TargetOptions targetOpts; diff --git a/lib/ClangImporter/ClangDiagnosticConsumer.cpp b/lib/ClangImporter/ClangDiagnosticConsumer.cpp index d682ae6dd5dab..dfd91c13e6469 100644 --- a/lib/ClangImporter/ClangDiagnosticConsumer.cpp +++ b/lib/ClangImporter/ClangDiagnosticConsumer.cpp @@ -34,10 +34,8 @@ namespace { public: ClangDiagRenderer(const clang::LangOptions &langOpts, - clang::DiagnosticOptions *diagOpts, - decltype(callback) fn) - : DiagnosticNoteRenderer(langOpts, diagOpts), - callback(fn) {} + clang::DiagnosticOptions &diagOpts, decltype(callback) fn) + : DiagnosticNoteRenderer(langOpts, diagOpts), callback(fn) {} private: /// Is this a diagnostic that doesn't do the user any good to show if it @@ -107,10 +105,9 @@ namespace { ClangDiagnosticConsumer::ClangDiagnosticConsumer( ClangImporter::Implementation &impl, - clang::DiagnosticOptions &clangDiagOptions, - bool dumpToStderr) - : TextDiagnosticPrinter(llvm::errs(), &clangDiagOptions), - ImporterImpl(impl), DumpToStderr(dumpToStderr) {} + clang::DiagnosticOptions &clangDiagOptions, bool dumpToStderr) + : TextDiagnosticPrinter(llvm::errs(), clangDiagOptions), ImporterImpl(impl), + DumpToStderr(dumpToStderr) {} void ClangDiagnosticConsumer::HandleDiagnostic( clang::DiagnosticsEngine::Level clangDiagLevel, @@ -179,7 +176,7 @@ void ClangDiagnosticConsumer::HandleDiagnostic( assert(clangDiag.hasSourceManager()); auto clangCI = ImporterImpl.getClangInstance(); ClangDiagRenderer renderer(clangCI->getLangOpts(), - &clangCI->getDiagnosticOpts(), emitDiag); + clangCI->getDiagnosticOpts(), emitDiag); clang::FullSourceLoc clangDiagLoc(clangDiag.getLocation(), clangDiag.getSourceManager()); renderer.emitDiagnostic(clangDiagLoc, clangDiagLevel, message, diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 12b5f536ac924..a90cd5716d6de 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -984,10 +984,11 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) { // will try to free it. invocation->getPreprocessorOpts().RemappedFileBuffers.clear(); + clang::DiagnosticOptions diagOpts; CI.setInvocation(std::move(invocation)); CI.setTarget(&Impl.Instance->getTarget()); CI.setDiagnostics(&*clang::CompilerInstance::createDiagnostics( - Impl.Instance->getVirtualFileSystem(), new clang::DiagnosticOptions())); + Impl.Instance->getVirtualFileSystem(), diagOpts)); // Note: Reusing the file manager is safe; this is a component that's already // reused when building PCM files for the module cache. @@ -1139,13 +1140,11 @@ std::optional> ClangImporter::getClangCC1Arguments( // // The long-term client for Clang diagnostics is set up afterwards, after the // clang::CompilerInstance is created. - llvm::IntrusiveRefCntPtr tempDiagOpts{ - new clang::DiagnosticOptions}; - auto *tempDiagClient = - new ClangDiagnosticConsumer(Impl, *tempDiagOpts, - ctx.ClangImporterOpts.DumpClangDiagnostics); + clang::DiagnosticOptions tempDiagOpts; + auto *tempDiagClient = new ClangDiagnosticConsumer( + Impl, tempDiagOpts, ctx.ClangImporterOpts.DumpClangDiagnostics); auto clangDiags = clang::CompilerInstance::createDiagnostics( - *VFS, tempDiagOpts.get(), tempDiagClient, + *VFS, tempDiagOpts, tempDiagClient, /*owned*/ true); // If using direct cc1 module build, use extra args to setup ClangImporter. @@ -1265,10 +1264,10 @@ std::unique_ptr ClangImporter::createClangInvocation( // option here is either generated by dependency scanner or just round tripped // from `getClangCC1Arguments` so we don't expect it to fail. Use a simple // printing diagnostics consumer for debugging any unexpected error. - auto diagOpts = llvm::makeIntrusiveRefCnt(); + clang::DiagnosticOptions diagOpts; clang::DiagnosticsEngine clangDiags( new clang::DiagnosticIDs(), diagOpts, - new clang::TextDiagnosticPrinter(llvm::errs(), diagOpts.get())); + new clang::TextDiagnosticPrinter(llvm::errs(), diagOpts)); // Finally, use the CC1 command-line and the diagnostic engine // to instantiate our Invocation. @@ -4161,8 +4160,8 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const { }); clang::CompilerInvocation instance; - clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), - new clang::DiagnosticOptions(), + clang::DiagnosticOptions diagOpts; + clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), diagOpts, new clang::IgnoringDiagConsumer()); bool success = clang::CompilerInvocation::CreateFromArgs(instance, clangArgs, clangDiags); diff --git a/lib/ClangImporter/ClangIncludePaths.cpp b/lib/ClangImporter/ClangIncludePaths.cpp index 9939333443443..f976707de874d 100644 --- a/lib/ClangImporter/ClangIncludePaths.cpp +++ b/lib/ClangImporter/ClangIncludePaths.cpp @@ -130,9 +130,10 @@ ClangImporter::createClangDriver( auto diagVFS = vfs ? vfs : llvm::vfs::getRealFileSystem(); + clang::DiagnosticOptions diagOpts; auto *silentDiagConsumer = new clang::DiagnosticConsumer(); auto clangDiags = clang::CompilerInstance::createDiagnostics( - *diagVFS, new clang::DiagnosticOptions(), silentDiagConsumer); + *diagVFS, diagOpts, silentDiagConsumer); clang::driver::Driver clangDriver(ClangImporterOpts.clangPath, LangOpts.Target.str(), *clangDiags, "clang LLVM compiler", vfs); diff --git a/lib/ClangImporter/ClangModuleDependencyScanner.cpp b/lib/ClangImporter/ClangModuleDependencyScanner.cpp index aad5dbc8c0a1a..a0afe28da89e9 100644 --- a/lib/ClangImporter/ClangModuleDependencyScanner.cpp +++ b/lib/ClangImporter/ClangModuleDependencyScanner.cpp @@ -228,8 +228,8 @@ void ClangImporter::getBridgingHeaderOptions( // Round-trip clang args to canonicalize and clear the options that swift // compiler doesn't need. clang::CompilerInvocation depsInvocation; - clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), - new clang::DiagnosticOptions(), + clang::DiagnosticOptions diagOpts; + clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), diagOpts, new clang::IgnoringDiagConsumer()); llvm::SmallVector clangArgs; diff --git a/lib/IDETool/CompilerInvocation.cpp b/lib/IDETool/CompilerInvocation.cpp index f16c441b4f12a..1e1dfa05ace27 100644 --- a/lib/IDETool/CompilerInvocation.cpp +++ b/lib/IDETool/CompilerInvocation.cpp @@ -267,15 +267,12 @@ bool ide::initCompilerInvocation( bool ide::initInvocationByClangArguments(ArrayRef ArgList, CompilerInvocation &Invok, std::string &Error) { - llvm::IntrusiveRefCntPtr DiagOpts{ - new clang::DiagnosticOptions() - }; - const auto VFS = llvm::vfs::getRealFileSystem(); clang::TextDiagnosticBuffer DiagBuf; + clang::DiagnosticOptions DiagOpts; llvm::IntrusiveRefCntPtr ClangDiags = - clang::CompilerInstance::createDiagnostics(*VFS, DiagOpts.get(), &DiagBuf, + clang::CompilerInstance::createDiagnostics(*VFS, DiagOpts, &DiagBuf, /*ShouldOwnClient=*/false); // Clang expects this to be like an actual command line. So we need to pass in diff --git a/lib/Migrator/Migrator.cpp b/lib/Migrator/Migrator.cpp index 034c056dc370a..857e30eb3dead 100644 --- a/lib/Migrator/Migrator.cpp +++ b/lib/Migrator/Migrator.cpp @@ -191,11 +191,11 @@ bool Migrator::performSyntacticPasses(SyntacticPassOptions Opts) { llvm::IntrusiveRefCntPtr DummyClangDiagIDs { new clang::DiagnosticIDs() }; - auto ClangDiags = - std::make_unique(DummyClangDiagIDs, - new clang::DiagnosticOptions, - new clang::DiagnosticConsumer(), - /*ShouldOwnClient=*/true); + + clang::DiagnosticOptions diagOpts; + auto ClangDiags = std::make_unique( + DummyClangDiagIDs, diagOpts, new clang::DiagnosticConsumer(), + /*ShouldOwnClient=*/true); clang::SourceManager ClangSourceManager { *ClangDiags, ClangFileManager }; clang::LangOptions ClangLangOpts; From b8b60f159ab0436f9b18d9157fa359a605510baa Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 16:08:32 +0100 Subject: [PATCH 04/14] AST: Adjust for renamed/removed `llvm::Intrinsic::IITDescriptor` cases See https://github.com/llvm/llvm-project/pull/141492 --- lib/AST/Builtins.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp index 216f3a6cdb83c..73b7b3587c2ae 100644 --- a/lib/AST/Builtins.cpp +++ b/lib/AST/Builtins.cpp @@ -2497,7 +2497,6 @@ Type IntrinsicTypeDecoder::decodeImmediate() { case IITDescriptor::Metadata: case IITDescriptor::ExtendArgument: case IITDescriptor::TruncArgument: - case IITDescriptor::HalfVecArgument: case IITDescriptor::VarArg: case IITDescriptor::Token: case IITDescriptor::VecOfAnyPtrsToElt: @@ -2506,9 +2505,7 @@ Type IntrinsicTypeDecoder::decodeImmediate() { case IITDescriptor::Subdivide4Argument: case IITDescriptor::PPCQuad: case IITDescriptor::AArch64Svcount: - case IITDescriptor::OneThirdVecArgument: - case IITDescriptor::OneFifthVecArgument: - case IITDescriptor::OneSeventhVecArgument: + case IITDescriptor::OneNthEltsVecArgument: // These types cannot be expressed in swift yet. return Type(); From 6cbd6024cd1864cd28bd89ee2a395bb897a9cd9a Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 16:09:29 +0100 Subject: [PATCH 05/14] Adjust includes of renamed Clang file See https://github.com/llvm/llvm-project/commit/3a42cbd47d3e92b8794378d2a0e8ec7ae81950d7 (No PR?!) --- lib/AST/ClangTypeConverter.cpp | 2 +- lib/ClangImporter/ClangAdapter.cpp | 2 +- lib/ClangImporter/ImportType.cpp | 2 +- lib/IRGen/GenCall.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/AST/ClangTypeConverter.cpp b/lib/AST/ClangTypeConverter.cpp index 89f9cb8cd234a..d8ee705acabe2 100644 --- a/lib/AST/ClangTypeConverter.cpp +++ b/lib/AST/ClangTypeConverter.cpp @@ -71,7 +71,7 @@ getClangBuiltinTypeFromKind(const clang::ASTContext &context, #define SVE_TYPE(Name, Id, SingletonId) \ case clang::BuiltinType::Id: \ return context.SingletonId; -#include "clang/Basic/AArch64SVEACLETypes.def" +#include "clang/Basic/AArch64ACLETypes.def" #define PPC_VECTOR_TYPE(Name, Id, Size) \ case clang::BuiltinType::Id: \ return context.Id##Ty; diff --git a/lib/ClangImporter/ClangAdapter.cpp b/lib/ClangImporter/ClangAdapter.cpp index 691eef5ae1d43..363425226914e 100644 --- a/lib/ClangImporter/ClangAdapter.cpp +++ b/lib/ClangImporter/ClangAdapter.cpp @@ -428,7 +428,7 @@ OmissionTypeName importer::getClangTypeNameForOmission(clang::ASTContext &ctx, // ARM SVE builtin types that don't have Swift equivalents. #define SVE_TYPE(Name, Id, ...) case clang::BuiltinType::Id: -#include "clang/Basic/AArch64SVEACLETypes.def" +#include "clang/Basic/AArch64ACLETypes.def" return OmissionTypeName(); // PPC MMA builtin types that don't have Swift equivalents. diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index b919d223316cf..cdf6a647b4f1a 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -347,7 +347,7 @@ namespace { // ARM SVE builtin types that don't have Swift equivalents. #define SVE_TYPE(Name, Id, ...) case clang::BuiltinType::Id: -#include "clang/Basic/AArch64SVEACLETypes.def" +#include "clang/Basic/AArch64ACLETypes.def" return Type(); // PPC SVE builtin types that don't have Swift equivalents. diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 79e0a9b3f6ca2..1abb69aa4857a 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -1322,7 +1322,7 @@ namespace { // We should never see ARM SVE types at all. #define SVE_TYPE(Name, Id, ...) case clang::BuiltinType::Id: -#include "clang/Basic/AArch64SVEACLETypes.def" +#include "clang/Basic/AArch64ACLETypes.def" llvm_unreachable("ARM SVE type in ABI lowering"); // We should never see PPC MMA types at all. From 0a72c3921a6762948c19dae3642f725318e5a1ec Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 17:19:50 +0100 Subject: [PATCH 06/14] ClangImporter: Adjust code after removal of `clang::CompilerInstance::setInvocation` See https://github.com/llvm/llvm-project/pull/137668 --- lib/ClangImporter/ClangImporter.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index a90cd5716d6de..ec904816aed3f 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -966,10 +966,8 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) { // FIXME: The following attempts to do an initial ReadAST invocation to verify // the PCH, without causing trouble for the existing CompilerInstance. // Look into combining creating the ASTReader along with verification + update - // if necessary, so that we can create and use one ASTReader in the common case - // when there is no need for update. - clang::CompilerInstance CI(Impl.Instance->getPCHContainerOperations(), - &Impl.Instance->getModuleCache()); + // if necessary, so that we can create and use one ASTReader in the common + // case when there is no need for update. auto invocation = std::make_shared(*Impl.Invocation); invocation->getPreprocessorOpts().DisablePCHOrModuleValidation = @@ -985,7 +983,9 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) { invocation->getPreprocessorOpts().RemappedFileBuffers.clear(); clang::DiagnosticOptions diagOpts; - CI.setInvocation(std::move(invocation)); + clang::CompilerInstance CI(std::move(invocation), + Impl.Instance->getPCHContainerOperations(), + &Impl.Instance->getModuleCache()); CI.setTarget(&Impl.Instance->getTarget()); CI.setDiagnostics(&*clang::CompilerInstance::createDiagnostics( Impl.Instance->getVirtualFileSystem(), diagOpts)); @@ -1363,12 +1363,10 @@ ClangImporter::create(ASTContext &ctx, std::make_unique()); PCHContainerOperations->registerReader( std::make_unique()); - importer->Impl.Instance.reset( - new clang::CompilerInstance(std::move(PCHContainerOperations))); + importer->Impl.Instance.reset(new clang::CompilerInstance( + importer->Impl.Invocation, std::move(PCHContainerOperations))); } auto &instance = *importer->Impl.Instance; - instance.setInvocation(importer->Impl.Invocation); - if (tracker) instance.addDependencyCollector(tracker->getClangCollector()); @@ -1898,9 +1896,8 @@ std::string ClangImporter::getBridgingHeaderContents( clang::FileManager &fileManager = Impl.Instance->getFileManager(); clang::CompilerInstance rewriteInstance( - Impl.Instance->getPCHContainerOperations(), - &Impl.Instance->getModuleCache()); - rewriteInstance.setInvocation(invocation); + std::move(invocation), Impl.Instance->getPCHContainerOperations(), + &Impl.Instance->getModuleCache()); rewriteInstance.createDiagnostics(fileManager.getVirtualFileSystem(), new clang::IgnoringDiagConsumer); rewriteInstance.setFileManager(&fileManager); @@ -2004,9 +2001,8 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() { clang::FileManager &fileManager = Impl.Instance->getFileManager(); auto clonedInstance = std::make_unique( - Impl.Instance->getPCHContainerOperations(), - &Impl.Instance->getModuleCache()); - clonedInstance->setInvocation(std::move(invocation)); + std::move(invocation), Impl.Instance->getPCHContainerOperations(), + &Impl.Instance->getModuleCache()); clonedInstance->createDiagnostics(fileManager.getVirtualFileSystem(), &Impl.Instance->getDiagnosticClient(), /*ShouldOwnClient=*/false); From 1a0e390f5aaebe40b5043d5de7e425f7fda119b4 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 17:26:25 +0100 Subject: [PATCH 07/14] ClangImporter: Adjust references to cases of moved enum `clang::Sema::AllocationFunctionScope` See https://github.com/llvm/llvm-project/commit/461255e0c17265141009437ba3887f49f9838a40 --- lib/ClangImporter/SwiftDeclSynthesizer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ClangImporter/SwiftDeclSynthesizer.cpp b/lib/ClangImporter/SwiftDeclSynthesizer.cpp index 24e1a8d94e565..ecb631d5749ce 100644 --- a/lib/ClangImporter/SwiftDeclSynthesizer.cpp +++ b/lib/ClangImporter/SwiftDeclSynthesizer.cpp @@ -2563,9 +2563,10 @@ SwiftDeclSynthesizer::synthesizeStaticFactoryForCXXForeignRef( bool passAlignment = false; clang::Sema::SFINAETrap trap(clangSema); bool findingAllocFuncFailed = clangSema.FindAllocationFunctions( - cxxRecordDeclLoc, clang::SourceRange(), clang::Sema::AFS_Both, - clang::Sema::AFS_Both, cxxRecordTy, /*IsArray=*/false, passAlignment, - clang::MultiExprArg(), operatorNew, operatorDelete, + cxxRecordDeclLoc, clang::SourceRange(), + clang::AllocationFunctionScope::Both, + clang::AllocationFunctionScope::Both, cxxRecordTy, /*IsArray=*/false, + passAlignment, clang::MultiExprArg(), operatorNew, operatorDelete, /*Diagnose=*/false); if (trap.hasErrorOccurred() || findingAllocFuncFailed || !operatorNew || operatorNew->isDeleted() || From 85c344b8e0030155445602bee36b8386b4e05e08 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 17:34:55 +0100 Subject: [PATCH 08/14] ClangImporter: Adjust references to renamed `clang::LifetimeCaptureByAttr` cases See https://github.com/llvm/llvm-project/pull/142195 --- lib/ClangImporter/ImportDecl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index c51160348cb60..1433dbcbbe6b9 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -4219,14 +4219,14 @@ namespace { for (auto param : attr->params()) { // FIXME: Swift assumes no escaping to globals. We should diagnose // this. - if (param == clang::LifetimeCaptureByAttr::GLOBAL || - param == clang::LifetimeCaptureByAttr::UNKNOWN || - param == clang::LifetimeCaptureByAttr::INVALID) + if (param == clang::LifetimeCaptureByAttr::Global || + param == clang::LifetimeCaptureByAttr::Unknown || + param == clang::LifetimeCaptureByAttr::Invalid) continue; paramHasAnnotation[idx] = true; if (isa(decl) && - param == clang::LifetimeCaptureByAttr::THIS) { + param == clang::LifetimeCaptureByAttr::This) { auto [it, inserted] = inheritedArgDependences.try_emplace( result->getSelfIndex(), SmallBitVector(dependencyVecSize)); it->second[idx] = true; From 01296faed80fc940408ab569f542a42613985a63 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 17:40:46 +0100 Subject: [PATCH 09/14] ClangImporter: Adjust references to moved enum `clang::LookupResult::LookupResultKind` See https://github.com/llvm/llvm-project/commit/ee29afe1e56d911f2fde54f5de141f4c4a0a1feb --- lib/ClangImporter/ImportMacro.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ClangImporter/ImportMacro.cpp b/lib/ClangImporter/ImportMacro.cpp index b11d6de5d8295..d8e1b48cd07d8 100644 --- a/lib/ClangImporter/ImportMacro.cpp +++ b/lib/ClangImporter/ImportMacro.cpp @@ -620,7 +620,7 @@ static ValueDecl *importMacro(ClangImporter::Implementation &impl, clang::LookupResult R(S, {{tok.getIdentifierInfo()}, {}}, clang::Sema::LookupAnyName); if (S.LookupName(R, S.TUScope)) - if (R.getResultKind() == clang::LookupResult::LookupResultKind::Found) + if (R.getResultKind() == clang::LookupResultKind::Found) if (const auto *VD = dyn_cast(R.getFoundDecl())) return importDeclAlias(impl, DC, VD, name); } From 70948738823e9f2384c44647aa8978d9ce35ff45 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 17:52:58 +0100 Subject: [PATCH 10/14] ClangImporter: Adjust call to refactored `clangSema.FindAllocationFunctions` See https://github.com/llvm/llvm-project/pull/113510 --- lib/ClangImporter/SwiftDeclSynthesizer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ClangImporter/SwiftDeclSynthesizer.cpp b/lib/ClangImporter/SwiftDeclSynthesizer.cpp index ecb631d5749ce..ab2d679f4a80e 100644 --- a/lib/ClangImporter/SwiftDeclSynthesizer.cpp +++ b/lib/ClangImporter/SwiftDeclSynthesizer.cpp @@ -2560,13 +2560,13 @@ SwiftDeclSynthesizer::synthesizeStaticFactoryForCXXForeignRef( clang::FunctionDecl *operatorNew = nullptr; clang::FunctionDecl *operatorDelete = nullptr; - bool passAlignment = false; + clang::ImplicitAllocationParameters IAP(clang::AlignedAllocationMode::No); clang::Sema::SFINAETrap trap(clangSema); bool findingAllocFuncFailed = clangSema.FindAllocationFunctions( cxxRecordDeclLoc, clang::SourceRange(), clang::AllocationFunctionScope::Both, - clang::AllocationFunctionScope::Both, cxxRecordTy, /*IsArray=*/false, - passAlignment, clang::MultiExprArg(), operatorNew, operatorDelete, + clang::AllocationFunctionScope::Both, cxxRecordTy, /*IsArray=*/false, IAP, + clang::MultiExprArg(), operatorNew, operatorDelete, /*Diagnose=*/false); if (trap.hasErrorOccurred() || findingAllocFuncFailed || !operatorNew || operatorNew->isDeleted() || From 6e9d9e175ddd1a5d24bfe6d65bc900534887fc29 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 18:17:09 +0100 Subject: [PATCH 11/14] ClangImporter: Conservatively handle new `clang::HLSLInlineSpirvType` type See https://github.com/llvm/llvm-project/pull/134034 --- lib/ClangImporter/ImportType.cpp | 10 ++++++++++ lib/ClangImporter/Serializability.cpp | 3 +++ lib/IRGen/GenCall.cpp | 1 + lib/Serialization/Deserialization.cpp | 3 +++ lib/Serialization/Serialization.cpp | 3 +++ 5 files changed, 20 insertions(+) diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index cdf6a647b4f1a..968a77dc2c0eb 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -429,6 +429,16 @@ namespace { return Type(); } + ImportResult + VisitHLSLInlineSpirvType(const clang::HLSLInlineSpirvType *type) { + Impl.addImportDiagnostic( + type, + Diagnostic(diag::unsupported_builtin_type, type->getTypeClassName()), + clang::SourceLocation()); + // FIXME: (?) HLSL types are not supported in Swift. + return Type(); + } + ImportResult VisitCountAttributedType(const clang::CountAttributedType *type) { return Visit(type->desugar()); diff --git a/lib/ClangImporter/Serializability.cpp b/lib/ClangImporter/Serializability.cpp index b57c47dce21c9..4802ea506f3d3 100644 --- a/lib/ClangImporter/Serializability.cpp +++ b/lib/ClangImporter/Serializability.cpp @@ -330,6 +330,9 @@ namespace { void writeTypeCoupledDeclRefInfo(clang::TypeCoupledDeclRefInfo info) { llvm_unreachable("TypeCoupledDeclRefInfo shouldn't be reached from swift"); } + void writeHLSLSpirvOperand(clang::SpirvOperand) { + llvm_unreachable("SpirvOperand shouldn't be reached from swift"); + } }; } diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 1abb69aa4857a..110ea0ebcbe94 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -1214,6 +1214,7 @@ namespace { case clang::Type::ArrayParameter: case clang::Type::HLSLAttributedResource: + case clang::Type::HLSLInlineSpirv: llvm_unreachable("HLSL type in ABI lowering"); diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 8758ea056e1b5..5f68689c40820 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -8478,6 +8478,9 @@ class SwiftToClangBasicReader : clang::TypeCoupledDeclRefInfo readTypeCoupledDeclRefInfo() { llvm_unreachable("TypeCoupledDeclRefInfo shouldn't be reached from swift"); } + clang::SpirvOperand readHLSLSpirvOperand() { + llvm_unreachable("SpirvOperand shouldn't be reached from swift"); + } }; } // end anonymous namespace diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 4d357ec9f2842..d2e378f8ffe35 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -6286,6 +6286,9 @@ class ClangToSwiftBasicWriter : void writeTypeCoupledDeclRefInfo(clang::TypeCoupledDeclRefInfo info) { llvm_unreachable("TypeCoupledDeclRefInfo shouldn't be reached from swift"); } + void writeHLSLSpirvOperand(clang::SpirvOperand) { + llvm_unreachable("SpirvOperand shouldn't be reached from swift"); + } }; } From 50ee3f421c086bc1b90017e2181c14404218dd3d Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 18:40:01 +0100 Subject: [PATCH 12/14] ClangImporter: Adjust code after transition to `clang::IdentifierLoc` See https://github.com/llvm/llvm-project/pull/136077 --- lib/ClangImporter/ClangImporter.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index ec904816aed3f..644ae6aa6d185 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -328,7 +328,7 @@ class BridgingPPTracker : public clang::PPCallbacks { return; SmallVector IdLocs; for (auto &P : Path) - IdLocs.push_back(P.second); + IdLocs.push_back(P.getLoc()); handleImport(ImportLoc, IdLocs, Imported); } @@ -2291,17 +2291,15 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang( auto realModuleName = SwiftContext.getRealModuleName(path.front().Item).str(); // Convert the Swift import path over to a Clang import path. - SmallVector, 4> - clangPath; + SmallVector clangPath; bool isTopModuleComponent = true; for (auto component : path) { StringRef item = isTopModuleComponent? realModuleName: component.Item.str(); isTopModuleComponent = false; - clangPath.emplace_back( - getClangPreprocessor().getIdentifierInfo(item), - exportSourceLoc(component.Loc)); + clangPath.emplace_back(exportSourceLoc(component.Loc), + getClangPreprocessor().getIdentifierInfo(item)); } auto &diagEngine = Instance->getDiagnostics(); @@ -2311,14 +2309,13 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang( auto loadModule = [&](clang::ModuleIdPath path, clang::Module::NameVisibilityKind visibility) -> clang::ModuleLoadResult { - auto importRAII = - diagClient.handleImport(clangPath.front().first, diagEngine, - importLoc); + auto importRAII = diagClient.handleImport( + clangPath.front().getIdentifierInfo(), diagEngine, importLoc); std::string preservedIndexStorePathOption; auto &clangFEOpts = Instance->getFrontendOpts(); if (!clangFEOpts.IndexStorePath.empty()) { - StringRef moduleName = path[0].first->getName(); + StringRef moduleName = path[0].getIdentifierInfo()->getName(); // Ignore the SwiftShims module for the index data. if (moduleName == SwiftContext.SwiftShimsModuleName.str()) { preservedIndexStorePathOption = clangFEOpts.IndexStorePath; From 7f8415bd363d309aec6d3cbd5a39747257f91e2b Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 11 Jun 2025 20:04:34 +0100 Subject: [PATCH 13/14] ClangImporter: Refactor Clang invocation path remapping after change to... ...`clang::tooling::dependencies::DepscanPrefixMapping::configurePrefixMapper` See https://github.com/swiftlang/llvm-project/pull/10723 --- lib/ClangImporter/ClangImporter.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 644ae6aa6d185..f16f6d4eb3fe9 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -26,6 +26,7 @@ #include "swift/AST/ConcreteDeclRef.h" #include "swift/AST/DiagnosticEngine.h" #include "swift/AST/DiagnosticsClangImporter.h" +#include "swift/AST/DiagnosticsFrontend.h" #include "swift/AST/DiagnosticsSema.h" #include "swift/AST/Evaluator.h" #include "swift/AST/IRGenOptions.h" @@ -4207,8 +4208,19 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const { if (!Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper.empty()) { // Remap all the paths if requested. llvm::PrefixMapper Mapper; - clang::tooling::dependencies::DepscanPrefixMapping::configurePrefixMapper( - Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper, Mapper); + SmallVector Prefixes; + if (auto E = llvm::MappedPrefix::transformJoined( + Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper, Prefixes)) { + // Take permanent ownership of this string. In general the diagnostic + // might outlive this function. + auto errorMessage = + Impl.SwiftContext.AllocateCopy(llvm::toString(std::move(E))); + Impl.SwiftContext.Diags.diagnose(SourceLoc(), diag::error_prefix_mapping, + errorMessage); + } + Mapper.addRange(Prefixes); + Mapper.sort(); + clang::tooling::dependencies::DepscanPrefixMapping::remapInvocationPaths( instance, Mapper); instance.getFrontendOpts().PathPrefixMappings.clear(); From b58d10c6828817adeffc7470a1e9ab3b9e5bffec Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Thu, 12 Jun 2025 03:33:13 +0100 Subject: [PATCH 14/14] Add missing new method to `clang::serialization::DataStreamBasic{Reader,Writer}` subclasses See https://github.com/llvm/llvm-project/pull/134142 --- include/swift/ClangImporter/SwiftAbstractBasicReader.h | 5 +++++ include/swift/ClangImporter/SwiftAbstractBasicWriter.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/swift/ClangImporter/SwiftAbstractBasicReader.h b/include/swift/ClangImporter/SwiftAbstractBasicReader.h index b5063c1c43493..8e31db659d2c1 100644 --- a/include/swift/ClangImporter/SwiftAbstractBasicReader.h +++ b/include/swift/ClangImporter/SwiftAbstractBasicReader.h @@ -64,6 +64,11 @@ class DataStreamBasicReader return uint32_t(asImpl().readUInt64()); } + clang::UnsignedOrNone readUnsignedOrNone() { + return clang::UnsignedOrNone::fromInternalRepresentation( + unsigned(asImpl().readUInt64())); + } + clang::Selector readSelector() { uint64_t numArgsPlusOne = asImpl().readUInt64(); diff --git a/include/swift/ClangImporter/SwiftAbstractBasicWriter.h b/include/swift/ClangImporter/SwiftAbstractBasicWriter.h index be8e2bf3c0e57..f636cba5907ba 100644 --- a/include/swift/ClangImporter/SwiftAbstractBasicWriter.h +++ b/include/swift/ClangImporter/SwiftAbstractBasicWriter.h @@ -61,6 +61,10 @@ class DataStreamBasicWriter asImpl().writeUInt64(uint64_t(value)); } + void writeUnsignedOrNone(clang::UnsignedOrNone value) { + asImpl().writeUInt64(uint64_t(value.toInternalRepresentation())); + } + void writeSelector(clang::Selector selector) { if (selector.isNull()) { asImpl().writeUInt64(0);