diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index fbb582fe86018..85b515f2ef9cb 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -702,7 +702,9 @@ pub(crate) fn global_llvm_features(sess: &Session, only_base_features: bool) -> features_string }; - features.extend(features_string.split(',').map(String::from)); + if !features_string.is_empty() { + features.extend(features_string.split(',').map(String::from)); + } } Some(_) | None => {} }; diff --git a/tests/run-make/target-cpu-native/foo.rs b/tests/run-make/target-cpu-native/foo.rs index f328e4d9d04c3..5abcd25abc3f3 100644 --- a/tests/run-make/target-cpu-native/foo.rs +++ b/tests/run-make/target-cpu-native/foo.rs @@ -1 +1,9 @@ fn main() {} + +// This forces explicit emission of a +neon target feature on targets +// where it is implied by the target-cpu, like aarch64-apple-darwin. +// This is a regression test for #153397. +#[cfg(target_feature = "neon")] +#[target_feature(enable = "neon")] +#[unsafe(no_mangle)] +pub fn with_neon() {} diff --git a/tests/run-make/target-cpu-native/rmake.rs b/tests/run-make/target-cpu-native/rmake.rs index 7b7974f309789..5791bf01bba2b 100644 --- a/tests/run-make/target-cpu-native/rmake.rs +++ b/tests/run-make/target-cpu-native/rmake.rs @@ -8,7 +8,12 @@ use run_make_support::{run, rustc}; fn main() { - let out = rustc().input("foo.rs").arg("-Ctarget-cpu=native").run().stderr_utf8(); + let out = rustc() + .input("foo.rs") + .arg("-Ctarget-cpu=native") + .arg("-Zverify-llvm-ir") + .run() + .stderr_utf8(); run("foo"); // There should be zero warnings emitted - the bug would cause "unknown CPU `native`" // to be printed out.