Skip to content

Commit 1e6ef24

Browse files
Rollup merge of #144143 - Gelbpunkt:target-features-crt-static, r=RalfJung
Fix `-Ctarget-feature`s getting ignored after `crt-static` The current behaviour introduced by commit a50a3b8 would discard any target features specified after `crt-static` (the only member of `RUSTC_SPECIFIC_FEATURES`). This is because it returned instead of continuing processing the next feature. I wasn't entirely sure how the regression test should look like, but this one should do. If anyone has some suggestions, I'm happy to learn, it's my first test :) I've confirmed that the test fails without the fix on `powerpc64le-unknown-linux-musl` and `x86_64-unknown-linux-gnu`. cc ``@RalfJung``
2 parents 2abca9c + 1b35d5f commit 1e6ef24

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ fn parse_rust_feature_flag<'a>(
149149
if let Some(base_feature) = feature.strip_prefix('+') {
150150
// Skip features that are not target features, but rustc features.
151151
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
152-
return;
152+
continue;
153153
}
154154

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

162162
// If `f1` implies `f2`, then `!f2` implies `!f1` -- this is standard logical
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test to ensure that specifying a value for crt-static in target features
2+
// does not result in skipping the features following it.
3+
// This is a regression test for #144143
4+
5+
//@ add-core-stubs
6+
//@ needs-llvm-components: x86
7+
//@ compile-flags: --target=x86_64-unknown-linux-gnu
8+
//@ compile-flags: -Ctarget-feature=+crt-static,+avx2
9+
10+
#![crate_type = "rlib"]
11+
#![feature(no_core, rustc_attrs, lang_items)]
12+
#![no_core]
13+
14+
extern crate minicore;
15+
use minicore::*;
16+
17+
#[rustc_builtin_macro]
18+
macro_rules! compile_error {
19+
() => {};
20+
}
21+
22+
#[cfg(target_feature = "avx2")]
23+
compile_error!("+avx2");
24+
//~^ ERROR: +avx2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: +avx2
2+
--> $DIR/crt-static-with-target-features-works.rs:23:1
3+
|
4+
LL | compile_error!("+avx2");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)