From 4d7c784caf1964d75cc41f8243560fb3553f2474 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 29 Oct 2025 13:43:14 +0000 Subject: [PATCH] Handle default features and -Ctarget-features in the dummy backend This prevents a warning about ABI relevant target features not being set on x86 and arm. In addition it is required for miri to report correct features in is_*_feature_detected!() if miri switches to the dummy backend. --- compiler/rustc_interface/src/util.rs | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 5e9cb42365049..56c3f65d8ae8e 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -9,8 +9,9 @@ use rustc_ast as ast; use rustc_attr_parsing::{ShouldEmit, validate_attr}; use rustc_codegen_ssa::back::archive::ArArchiveBuilderBuilder; use rustc_codegen_ssa::back::link::link_binary; +use rustc_codegen_ssa::target_features::{self, cfg_target_feature}; use rustc_codegen_ssa::traits::CodegenBackend; -use rustc_codegen_ssa::{CodegenResults, CrateInfo}; +use rustc_codegen_ssa::{CodegenResults, CrateInfo, TargetConfig}; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::jobserver::Proxy; use rustc_data_structures::sync; @@ -354,6 +355,33 @@ impl CodegenBackend for DummyCodegenBackend { "dummy" } + fn target_config(&self, sess: &Session) -> TargetConfig { + let (target_features, unstable_target_features) = cfg_target_feature(sess, |feature| { + // This is a standin for the list of features a backend is expected to enable. + // It would be better to parse target.features instead and handle implied features, + // but target.features is a list of LLVM target features, not Rust target features. + // The dummy backend doesn't know the mapping between LLVM and Rust target features. + sess.target.abi_required_features().required.contains(&feature) + }); + + // To report warnings about unknown features + target_features::flag_to_backend_features::<0>( + sess, + true, + |_| Default::default(), + |_, _| {}, + ); + + TargetConfig { + target_features, + unstable_target_features, + has_reliable_f16: true, + has_reliable_f16_math: true, + has_reliable_f128: true, + has_reliable_f128_math: true, + } + } + fn supported_crate_types(&self, _sess: &Session) -> Vec { // This includes bin despite failing on the link step to ensure that you // can still get the frontend handling for binaries. For all library