From 8bec5bb5adaa1f5a0bc3683fee5f77a5fdac539b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 11 May 2025 12:50:48 +0200 Subject: cg_gcc: properly populate cfg(target_features) with -Ctarget-features --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'compiler/rustc_codegen_llvm') diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index ee78c310b0d..bc2165fa829 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -7,6 +7,7 @@ use std::{ptr, slice, str}; use libc::c_int; use rustc_codegen_ssa::base::wants_wasm_eh; +use rustc_codegen_ssa::target_features::cfg_target_feature; use rustc_codegen_ssa::{TargetConfig, target_features}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::small_c_str::SmallCStr; @@ -331,24 +332,23 @@ pub(crate) fn target_config(sess: &Session) -> TargetConfig { // by LLVM. let target_machine = create_informational_target_machine(sess, true); - let (unstable_target_features, target_features) = - target_features::cfg_target_feature(sess, &sess.opts.cg.target_feature, |feature| { - if let Some(feat) = to_llvm_features(sess, feature) { - // All the LLVM features this expands to must be enabled. - for llvm_feature in feat { - let cstr = SmallCStr::new(llvm_feature); - // `LLVMRustHasFeature` is moderately expensive. On targets with many - // features (e.g. x86) these calls take a non-trivial fraction of runtime - // when compiling very small programs. - if !unsafe { llvm::LLVMRustHasFeature(target_machine.raw(), cstr.as_ptr()) } { - return false; - } + let (unstable_target_features, target_features) = cfg_target_feature(sess, |feature| { + if let Some(feat) = to_llvm_features(sess, feature) { + // All the LLVM features this expands to must be enabled. + for llvm_feature in feat { + let cstr = SmallCStr::new(llvm_feature); + // `LLVMRustHasFeature` is moderately expensive. On targets with many + // features (e.g. x86) these calls take a non-trivial fraction of runtime + // when compiling very small programs. + if !unsafe { llvm::LLVMRustHasFeature(target_machine.raw(), cstr.as_ptr()) } { + return false; } - true - } else { - false } - }); + true + } else { + false + } + }); let mut cfg = TargetConfig { target_features, -- cgit 1.4.1-3-g733a5