about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-02 03:03:22 +0000
committerbors <bors@rust-lang.org>2022-03-02 03:03:22 +0000
commit39a3b527674c1c8d2b9d3edc0cfae67abe6b3ecb (patch)
tree19cad78e9c5434d03b45ff81ef169449e409a12b /src
parentf0c4da49983aa699f715caf681e3154b445fb60b (diff)
parentdf701a292ce552fddad2048cfcb6edaf90222d85 (diff)
downloadrust-39a3b527674c1c8d2b9d3edc0cfae67abe6b3ecb.tar.gz
rust-39a3b527674c1c8d2b9d3edc0cfae67abe6b3ecb.zip
Auto merge of #87402 - nagisa:nagisa/request-feature-requests-for-features, r=estebank
Direct users towards using Rust target feature names in CLI

This PR consists of a couple of changes on how we handle target features.

In particular there is a bug-fix wherein we avoid passing through features that aren't prefixed by `+` or `-` to LLVM. These appear to be causing LLVM to assert, which is pretty poor a behaviour (and also makes it pretty clear we expect feature names to be prefixed).

The other commit, I anticipate to be somewhat more controversial is outputting a warning when users specify a LLVM-specific, or otherwise unknown, feature name on the CLI. In those situations we request users to either replace it with a known Rust feature name (e.g. `bmi` -> `bmi1`) or file a feature request. I've a couple motivations for this: first of all, if users are specifying these features on the command line, I'm pretty confident there is also a need for these features to be usable via `#[cfg(target_feature)]` machinery.  And second, we're growing a fair number of backends recently and having ability to provide some sort of unified-ish interface in this place seems pretty useful to me.

Sponsored by: standard.ai
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/target-feature/missing-plusminus-2.rs6
-rw-r--r--src/test/ui/target-feature/missing-plusminus-2.stderr6
-rw-r--r--src/test/ui/target-feature/missing-plusminus.rs2
-rw-r--r--src/test/ui/target-feature/missing-plusminus.stderr6
-rw-r--r--src/test/ui/target-feature/similar-feature-suggestion.rs6
-rw-r--r--src/test/ui/target-feature/similar-feature-suggestion.stderr7
-rw-r--r--src/test/ui/target-feature/tied-features-cli.one.stderr2
-rw-r--r--src/test/ui/target-feature/tied-features-cli.rs25
-rw-r--r--src/test/ui/target-feature/tied-features-cli.three.stderr2
-rw-r--r--src/test/ui/target-feature/tied-features-cli.two.stderr2
-rw-r--r--src/test/ui/target-feature/tied-features.rs12
-rw-r--r--src/test/ui/target-feature/tied-features.stderr4
12 files changed, 65 insertions, 15 deletions
diff --git a/src/test/ui/target-feature/missing-plusminus-2.rs b/src/test/ui/target-feature/missing-plusminus-2.rs
new file mode 100644
index 00000000000..13168728902
--- /dev/null
+++ b/src/test/ui/target-feature/missing-plusminus-2.rs
@@ -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]
diff --git a/src/test/ui/target-feature/missing-plusminus-2.stderr b/src/test/ui/target-feature/missing-plusminus-2.stderr
new file mode 100644
index 00000000000..5ed2652a06d
--- /dev/null
+++ b/src/test/ui/target-feature/missing-plusminus-2.stderr
@@ -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
+
diff --git a/src/test/ui/target-feature/missing-plusminus.rs b/src/test/ui/target-feature/missing-plusminus.rs
new file mode 100644
index 00000000000..efee6592923
--- /dev/null
+++ b/src/test/ui/target-feature/missing-plusminus.rs
@@ -0,0 +1,2 @@
+// compile-flags: -Ctarget-feature=banana --crate-type=rlib
+// build-pass
diff --git a/src/test/ui/target-feature/missing-plusminus.stderr b/src/test/ui/target-feature/missing-plusminus.stderr
new file mode 100644
index 00000000000..93abf350805
--- /dev/null
+++ b/src/test/ui/target-feature/missing-plusminus.stderr
@@ -0,0 +1,6 @@
+warning: unknown feature specified for `-Ctarget-feature`: `banana`
+   |
+   = note: features must begin with a `+` to enable or `-` to disable it
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/target-feature/similar-feature-suggestion.rs b/src/test/ui/target-feature/similar-feature-suggestion.rs
new file mode 100644
index 00000000000..4e4e2160cac
--- /dev/null
+++ b/src/test/ui/target-feature/similar-feature-suggestion.rs
@@ -0,0 +1,6 @@
+// compile-flags: -Ctarget-feature=+rdrnd --crate-type=rlib --target=x86_64-unknown-linux-gnu
+// build-pass
+// needs-llvm-components: x86
+
+#![feature(no_core)]
+#![no_core]
diff --git a/src/test/ui/target-feature/similar-feature-suggestion.stderr b/src/test/ui/target-feature/similar-feature-suggestion.stderr
new file mode 100644
index 00000000000..2f376065fdf
--- /dev/null
+++ b/src/test/ui/target-feature/similar-feature-suggestion.stderr
@@ -0,0 +1,7 @@
+warning: unknown feature specified for `-Ctarget-feature`: `rdrnd`
+   |
+   = note: it is still passed through to the codegen backend
+   = help: you might have meant: `rdrand`
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/target-feature/tied-features-cli.one.stderr b/src/test/ui/target-feature/tied-features-cli.one.stderr
index 2bc64a76aae..0cc901eecaa 100644
--- a/src/test/ui/target-feature/tied-features-cli.one.stderr
+++ b/src/test/ui/target-feature/tied-features-cli.one.stderr
@@ -1,4 +1,4 @@
-error: Target features paca, pacg must all be enabled or disabled together
+error: target features paca, pacg must all be enabled or disabled together
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/target-feature/tied-features-cli.rs b/src/test/ui/target-feature/tied-features-cli.rs
index ea09d4fc460..72b7e3da530 100644
--- a/src/test/ui/target-feature/tied-features-cli.rs
+++ b/src/test/ui/target-feature/tied-features-cli.rs
@@ -1,9 +1,20 @@
-// only-aarch64
-// revisions: one two three four
-//[one] compile-flags: -C target-feature=+paca
-//[two] compile-flags: -C target-feature=-pacg,+pacg
-//[three] compile-flags: -C target-feature=+paca,+pacg,-paca
-//[four] check-pass
-//[four] compile-flags: -C target-feature=-paca,+pacg -C target-feature=+paca
+// revisions: one two three
+// compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu
+// needs-llvm-components: aarch64
+//
+//
+// [one] check-fail
+// [one] compile-flags: -C target-feature=+paca
+// [two] check-fail
+// [two] compile-flags: -C target-feature=-pacg,+pacg
+// [three] check-fail
+// [three] compile-flags: -C target-feature=+paca,+pacg,-paca
+// [four] build-pass
+// [four] compile-flags: -C target-feature=-paca,+pacg -C target-feature=+paca
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang="sized"]
+trait Sized {}
 
 fn main() {}
diff --git a/src/test/ui/target-feature/tied-features-cli.three.stderr b/src/test/ui/target-feature/tied-features-cli.three.stderr
index 2bc64a76aae..0cc901eecaa 100644
--- a/src/test/ui/target-feature/tied-features-cli.three.stderr
+++ b/src/test/ui/target-feature/tied-features-cli.three.stderr
@@ -1,4 +1,4 @@
-error: Target features paca, pacg must all be enabled or disabled together
+error: target features paca, pacg must all be enabled or disabled together
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/target-feature/tied-features-cli.two.stderr b/src/test/ui/target-feature/tied-features-cli.two.stderr
index 2bc64a76aae..0cc901eecaa 100644
--- a/src/test/ui/target-feature/tied-features-cli.two.stderr
+++ b/src/test/ui/target-feature/tied-features-cli.two.stderr
@@ -1,4 +1,4 @@
-error: Target features paca, pacg must all be enabled or disabled together
+error: target features paca, pacg must all be enabled or disabled together
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/target-feature/tied-features.rs b/src/test/ui/target-feature/tied-features.rs
index 86400361db3..01353e9f70c 100644
--- a/src/test/ui/target-feature/tied-features.rs
+++ b/src/test/ui/target-feature/tied-features.rs
@@ -1,9 +1,15 @@
-// only-aarch64
 // build-fail
-
+// compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu
+// needs-llvm-components: aarch64
 #![feature(aarch64_target_feature, target_feature_11)]
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang="sized"]
+trait Sized {}
 
-fn main() {
+// FIXME: this should not need to be public.
+pub fn main() {
     #[target_feature(enable = "pacg")]
     //~^ ERROR must all be either enabled or disabled together
     unsafe fn inner() {}
diff --git a/src/test/ui/target-feature/tied-features.stderr b/src/test/ui/target-feature/tied-features.stderr
index 0b1460e0b75..6362c7ae60b 100644
--- a/src/test/ui/target-feature/tied-features.stderr
+++ b/src/test/ui/target-feature/tied-features.stderr
@@ -1,5 +1,5 @@
 error: the target features paca, pacg must all be either enabled or disabled together
-  --> $DIR/tied-features.rs:7:5
+  --> $DIR/tied-features.rs:13:5
    |
 LL |     #[target_feature(enable = "pacg")]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -7,7 +7,7 @@ LL |     #[target_feature(enable = "pacg")]
    = help: add the missing features in a `target_feature` attribute
 
 error: the target features paca, pacg must all be either enabled or disabled together
-  --> $DIR/tied-features.rs:19:1
+  --> $DIR/tied-features.rs:25:1
    |
 LL | #[target_feature(enable = "paca")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^