Skip to content

Fix -Ctarget-features getting ignored after crt-static #144143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ fn parse_rust_feature_flag<'a>(
if let Some(base_feature) = feature.strip_prefix('+') {
// Skip features that are not target features, but rustc features.
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
return;
continue;
}

callback(base_feature, sess.target.implied_target_features(base_feature), true)
} else if let Some(base_feature) = feature.strip_prefix('-') {
// Skip features that are not target features, but rustc features.
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
return;
continue;
}

// If `f1` implies `f2`, then `!f2` implies `!f1` -- this is standard logical
Expand Down
24 changes: 24 additions & 0 deletions tests/ui/cfg/crt-static-with-target-features-works.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Test to ensure that specifying a value for crt-static in target features
// does not result in skipping the features following it.
// This is a regression test for #144143

//@ add-core-stubs
//@ needs-llvm-components: x86
//@ compile-flags: --target=x86_64-unknown-linux-gnu
//@ compile-flags: -Ctarget-feature=+crt-static,+avx2

#![crate_type = "rlib"]
#![feature(no_core, rustc_attrs, lang_items)]
#![no_core]

extern crate minicore;
use minicore::*;

#[rustc_builtin_macro]
macro_rules! compile_error {
() => {};
}

#[cfg(target_feature = "avx2")]
compile_error!("+avx2");
//~^ ERROR: +avx2
8 changes: 8 additions & 0 deletions tests/ui/cfg/crt-static-with-target-features-works.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: +avx2
--> $DIR/crt-static-with-target-features-works.rs:23:1
|
LL | compile_error!("+avx2");
| ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Loading