1
Fork 0

Do not pass through features without +/- prefix

LLVM really dislikes this and will assert, saying something along the
lines of:

```
rustc: llvm/lib/MC/MCSubtargetInfo.cpp:60: void ApplyFeatureFlag(
  llvm::FeatureBitset&, llvm::StringRef, llvm::ArrayRef<llvm::SubtargetFeatureKV>
): Assertion
  `SubtargetFeatures::hasFlag(Feature) && "Feature flags should start with '+' or '-'"`
failed.
```
This commit is contained in:
Simonas Kazlauskas 2021-07-23 14:42:36 +03:00
parent 3b1fe7e7c9
commit dfcfaa4ec1
3 changed files with 28 additions and 17 deletions

View file

@ -221,7 +221,11 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
supported_target_features(sess) supported_target_features(sess)
.iter() .iter()
.filter_map(|&(feature, gate)| { .filter_map(|&(feature, gate)| {
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None } if sess.is_nightly_build() || gate.is_none() {
Some(feature)
} else {
None
}
}) })
.filter(|feature| { .filter(|feature| {
for llvm_feature in to_llvm_feature(sess, feature) { for llvm_feature in to_llvm_feature(sess, feature) {
@ -428,20 +432,15 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
} }
let filter = |s: &str| { let filter = |s: &str| {
if s.is_empty() { // features must start with a `+` or `-`.
return vec![]; let feature = match s.strip_prefix(&['+', '-'][..]) {
} None => return vec![],
let feature = strip(s); // Rustc-specific feature requests like `+crt-static` or `-crt-static`
if feature == s { // are not passed down to LLVM.
return vec![s.to_string()]; Some(feature) if RUSTC_SPECIFIC_FEATURES.contains(&feature) => return vec![],
} Some(feature) => feature,
};
// Rustc-specific feature requests like `+crt-static` or `-crt-static` // ... otherwise though we run through `to_llvm_feature` when
// are not passed down to LLVM.
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
return vec![];
}
// ... otherwise though we run through `to_llvm_feature` feature when
// passing requests down to LLVM. This means that all in-language // passing requests down to LLVM. This means that all in-language
// features also work on the command line instead of having two // features also work on the command line instead of having two
// different names when the LLVM name and the Rust name differ. // different names when the LLVM name and the Rust name differ.
@ -458,11 +457,11 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
check_tied_features(sess, &feats.iter().map(|f| (strip(f), !f.starts_with("-"))).collect()) check_tied_features(sess, &feats.iter().map(|f| (strip(f), !f.starts_with("-"))).collect())
{ {
sess.err(&format!( sess.err(&format!(
"Target features {} must all be enabled or disabled together", "target features {} must all be enabled or disabled together",
f.join(", ") f.join(", ")
)); ));
} }
features.extend(feats.iter().flat_map(|&f| filter(f))); features.extend(feats.iter().flat_map(&filter));
features features
} }

View file

@ -0,0 +1,6 @@
// compile-flags: -Ctarget-feature=rdrand --crate-type=rlib --target=x86_64-unknown-linux-gnu
// build-pass
// needs-llvm-components: x86
#![feature(no_core)]
#![no_core]

View file

@ -0,0 +1,6 @@
warning: unknown feature specified for `-Ctarget-feature`: `rdrand`
|
= note: features must begin with a `+` to enable or `-` to disable it
warning: 1 warning emitted