From 596d9853bb6c44c3ae290a40f792ee4ec54d1ea0 Mon Sep 17 00:00:00 2001 From: Devon Loehr Date: Mon, 4 May 2026 17:41:27 +0000 Subject: [PATCH] Adjust getMCSubtargetInfo signature for LLVM 23+ --- .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index c7e8f99465e1..643e4944bf78 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -91,8 +91,13 @@ extern "C" void LLVMRustTimeTraceProfilerFinish(const char *FileName) { extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM, const char *Feature) { TargetMachine *Target = unwrap(TM); +#if LLVM_VERSION_GE(23, 0) + const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo(); + return MCInfo.checkFeatures(std::string("+") + Feature); +#else const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); return MCInfo->checkFeatures(std::string("+") + Feature); +#endif } /// Check whether the target has a specific assembly mnemonic like `ret` or @@ -274,7 +279,11 @@ static llvm::DebugCompressionType fromRust(LLVMRustCompressionKind Kind) { extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, RustStringRef OutStr) { ArrayRef CPUTable = +#if LLVM_VERSION_GE(23, 0) + unwrap(TM)->getMCSubtargetInfo().getAllProcessorDescriptions(); +#else unwrap(TM)->getMCSubtargetInfo()->getAllProcessorDescriptions(); +#endif auto OS = RawRustStringOstream(OutStr); // Just print a bare list of target CPU names, and let Rust-side code handle @@ -286,9 +295,15 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) { const TargetMachine *Target = unwrap(TM); +#if LLVM_VERSION_GE(23, 0) + const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo(); + const ArrayRef FeatTable = + MCInfo.getAllProcessorFeatures(); +#else const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); const ArrayRef FeatTable = MCInfo->getAllProcessorFeatures(); +#endif return FeatTable.size(); } @@ -296,9 +311,15 @@ extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef TM, size_t Index, const char **Feature, const char **Desc) { const TargetMachine *Target = unwrap(TM); +#if LLVM_VERSION_GE(23, 0) + const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo(); + const ArrayRef FeatTable = + MCInfo.getAllProcessorFeatures(); +#else const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); const ArrayRef FeatTable = MCInfo->getAllProcessorFeatures(); +#endif const SubtargetFeatureKV Feat = FeatTable[Index]; *Feature = Feat.Key; *Desc = Feat.Desc;