Skip to content

Commit

Permalink
make this just a warning (for use with the -C flag) for now; also sho…
Browse files Browse the repository at this point in the history
…w a reason why it is forbidden
  • Loading branch information
RalfJung committed Sep 12, 2024
1 parent a69de2c commit 691bcaa
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/gcc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
// An unstable feature. Warn about using it.
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
}
Some((_, Stability::Forbidden, _)) => {
Some((_, Stability::Forbidden { .. }, _)) => {
sess.dcx().emit_err(ForbiddenCTargetFeature { feature });
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_llvm/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ codegen_llvm_dynamic_linking_with_lto =
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
codegen_llvm_forbidden_ctarget_feature =
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`: {$reason}
.note = this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
codegen_llvm_forbidden_ctarget_feature_issue = for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
codegen_llvm_from_llvm_diag = {$message}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ pub(crate) struct UnstableCTargetFeature<'a> {

#[derive(Diagnostic)]
#[diag(codegen_llvm_forbidden_ctarget_feature)]
#[note]
#[note(codegen_llvm_forbidden_ctarget_feature_issue)]
pub(crate) struct ForbiddenCTargetFeature<'a> {
pub feature: &'a str,
pub reason: &'a str,
}

#[derive(Subdiagnostic)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ pub(crate) fn global_llvm_features(
// An unstable feature. Warn about using it.
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
}
Some((_, Stability::Forbidden, _)) => {
sess.dcx().emit_err(ForbiddenCTargetFeature { feature });
Some((_, Stability::Forbidden { reason }, _)) => {
sess.dcx().emit_warn(ForbiddenCTargetFeature { feature, reason });
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ codegen_ssa_failed_to_write = failed to write {$path}: {$error}
codegen_ssa_field_associated_value_expected = associated value expected for `{$name}`
codegen_ssa_forbidden_target_feature =
target feature `{$feature}` cannot be toggled with `#[target_feature]`
target feature `{$feature}` cannot be toggled with `#[target_feature]`: {$reason}
codegen_ssa_ignoring_emit_path = ignoring emit path because multiple .{$extension} files were produced
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ pub struct ForbiddenTargetFeature<'a> {
#[primary_span]
pub span: Span,
pub feature: &'a str,
pub reason: &'a str,
}

#[derive(Diagnostic)]
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn from_target_feature_attr(

// Only allow features whose feature gates have been enabled.
let allowed = match stability {
Stability::Forbidden => false,
Stability::Forbidden { .. } => false,
Stability::Stable => true,
Stability::Unstable(sym::arm_target_feature) => rust_features.arm_target_feature,
Stability::Unstable(sym::hexagon_target_feature) => {
Expand Down Expand Up @@ -125,10 +125,11 @@ pub fn from_target_feature_attr(
)
.emit();
}
Stability::Forbidden => {
Stability::Forbidden { reason } => {
tcx.dcx().emit_err(errors::ForbiddenTargetFeature {
span: item.span(),
feature,
reason,
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum Stability {
Unstable(Symbol),
/// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be set in the basic
/// target definition. Used in particular for features that change the floating-point ABI.
Forbidden,
Forbidden { reason: &'static str },
}
use Stability::*;

Expand All @@ -38,7 +38,7 @@ impl<CTX> HashStable<CTX> for Stability {
Unstable(sym) => {
sym.hash_stable(hcx, hasher);
}
Forbidden => {}
Forbidden { .. } => {}
}
}
}
Expand All @@ -50,7 +50,7 @@ impl Stability {

/// Forbidden features are not supported.
pub fn is_supported(self) -> bool {
!matches!(self, Forbidden)
!matches!(self, Forbidden { .. })
}
}

Expand Down Expand Up @@ -101,13 +101,13 @@ const ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("dotprod", Unstable(sym::arm_target_feature), &["neon"]),
("dsp", Unstable(sym::arm_target_feature), &[]),
("fp-armv8", Unstable(sym::arm_target_feature), &["vfp4"]),
("fpregs", Forbidden, &[]), // changes float ABI
("fpregs", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
("i8mm", Unstable(sym::arm_target_feature), &["neon"]),
("mclass", Unstable(sym::arm_target_feature), &[]),
("neon", Unstable(sym::arm_target_feature), &["vfp3"]),
("rclass", Unstable(sym::arm_target_feature), &[]),
("sha2", Unstable(sym::arm_target_feature), &["neon"]),
("soft-float", Forbidden, &[]), // changes float ABI
("soft-float", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
// This is needed for inline assembly, but shouldn't be stabilized as-is
// since it should be enabled per-function using #[instruction_set], not
// #[target_feature].
Expand Down Expand Up @@ -366,7 +366,7 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("sha512", Unstable(sym::sha512_sm_x86), &["avx2"]),
("sm3", Unstable(sym::sha512_sm_x86), &["avx"]),
("sm4", Unstable(sym::sha512_sm_x86), &["avx2"]),
("soft-float", Forbidden, &[]), // changes float ABI
("soft-float", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
("sse", Stable, &[]),
("sse2", Stable, &["sse"]),
("sse3", Stable, &["sse2"]),
Expand All @@ -377,7 +377,7 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("tbm", Unstable(sym::tbm_target_feature), &[]),
("vaes", Unstable(sym::avx512_target_feature), &["avx2", "aes"]),
("vpclmulqdq", Unstable(sym::avx512_target_feature), &["avx", "pclmulqdq"]),
("x87", Forbidden, &[]), // changes float ABI
("x87", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
("xop", Unstable(sym::xop_target_feature), &[/*"fma4", */ "avx", "sse4a"]),
("xsave", Stable, &[]),
("xsavec", Stable, &["xsave"]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: target feature `soft-float` cannot be toggled with `#[target_feature]`
error: target feature `soft-float` cannot be toggled with `#[target_feature]`: unsound because it changes float ABI
--> $DIR/forbidden-target-feature-attribute.rs:10:18
|
LL | #[target_feature(enable = "soft-float")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
//@ needs-llvm-components: x86
//@ compile-flags: -Ctarget-feature=-soft-float
// For now this is just a warning.
//@ build-pass
#![feature(no_core, lang_items)]
#![no_std]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
error: target feature `soft-float` cannot be toggled with `-Ctarget-feature`
warning: target feature `soft-float` cannot be toggled with `-Ctarget-feature`: unsound because it changes float ABI
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

error: aborting due to 1 previous error
warning: 1 warning emitted

4 changes: 2 additions & 2 deletions tests/ui/target-feature/forbidden-target-feature-flag.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
//@ needs-llvm-components: x86
//@ compile-flags: -Ctarget-feature=+soft-float
// For now this is just a warning.
//@ build-pass
#![feature(no_core, lang_items)]
#![no_std]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

fn main() {}
7 changes: 5 additions & 2 deletions tests/ui/target-feature/forbidden-target-feature-flag.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
error: target feature `soft-float` cannot be toggled with `-Ctarget-feature`
warning: target feature `soft-float` cannot be toggled with `-Ctarget-feature`: unsound because it changes float ABI
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

error: aborting due to 1 previous error
warning: 1 warning emitted

0 comments on commit 691bcaa

Please sign in to comment.