Skip to content

Commit 3fe0d85

Browse files
committed
make enabling the neon target feature a FCW
1 parent 25a7c41 commit 3fe0d85

File tree

7 files changed

+120
-13
lines changed

7 files changed

+120
-13
lines changed

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not implemented yet for L4Bender
22
3+
codegen_ssa_aarch64_softfloat_neon = enabling the `neon` target feature on the current target is unsound due to ABI issues
4+
35
codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}
46
57
codegen_ssa_aix_strip_not_used = using host's `strip` binary to cross-compile to AIX which is not guaranteed to work

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
299299
}
300300
from_target_feature_attr(
301301
tcx,
302+
did,
302303
attr,
303304
rust_target_features,
304305
&mut codegen_fn_attrs.target_features,

compiler/rustc_codegen_ssa/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1316,3 +1316,7 @@ pub(crate) struct XcrunSdkPathWarning {
13161316
pub sdk_name: &'static str,
13171317
pub stderr: String,
13181318
}
1319+
1320+
#[derive(LintDiagnostic)]
1321+
#[diag(codegen_ssa_aarch64_softfloat_neon)]
1322+
pub(crate) struct Aarch64SoftfloatNeon;

compiler/rustc_codegen_ssa/src/target_features.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
88
use rustc_middle::middle::codegen_fn_attrs::TargetFeature;
99
use rustc_middle::query::Providers;
1010
use rustc_middle::ty::TyCtxt;
11+
use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON;
1112
use rustc_session::parse::feature_err;
1213
use rustc_span::{Span, Symbol, sym};
1314
use rustc_target::target_features::{self, Stability};
@@ -18,6 +19,7 @@ use crate::errors;
1819
/// Enabled target features are added to `target_features`.
1920
pub(crate) fn from_target_feature_attr(
2021
tcx: TyCtxt<'_>,
22+
did: LocalDefId,
2123
attr: &hir::Attribute,
2224
rust_target_features: &UnordMap<String, target_features::Stability>,
2325
target_features: &mut Vec<TargetFeature>,
@@ -92,11 +94,22 @@ pub(crate) fn from_target_feature_attr(
9294
// generating code so "it's fine".
9395
if !tcx.sess.opts.actually_rustdoc {
9496
if abi_feature_constraints.incompatible.contains(&name.as_str()) {
95-
tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
96-
span: item.span(),
97-
feature: name.as_str(),
98-
reason: "this feature is incompatible with the target ABI",
99-
});
97+
// For "neon" specifically, we emit an FCW instead of a hard error.
98+
// See <https://github.com/rust-lang/rust/issues/134375>.
99+
if name.as_str() == "neon" {
100+
tcx.emit_node_span_lint(
101+
AARCH64_SOFTFLOAT_NEON,
102+
tcx.local_def_id_to_hir_id(did),
103+
item.span(),
104+
errors::Aarch64SoftfloatNeon,
105+
);
106+
} else {
107+
tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
108+
span: item.span(),
109+
feature: name.as_str(),
110+
reason: "this feature is incompatible with the target ABI",
111+
});
112+
}
100113
}
101114
}
102115
target_features.push(TargetFeature { name, implied: name != feature_sym })

compiler/rustc_lint_defs/src/builtin.rs

+50-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ declare_lint_pass! {
1616
/// that are used by other parts of the compiler.
1717
HardwiredLints => [
1818
// tidy-alphabetical-start
19+
AARCH64_SOFTFLOAT_NEON,
1920
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
2021
AMBIGUOUS_ASSOCIATED_ITEMS,
2122
AMBIGUOUS_GLOB_IMPORTS,
@@ -5069,14 +5070,14 @@ declare_lint! {
50695070
///
50705071
/// ```text
50715072
/// error: this function function definition is affected by the wasm ABI transition: it passes an argument of non-scalar type `MyType`
5072-
/// --> $DIR/wasm_c_abi_transition.rs:17:1
5073-
/// |
5074-
/// | pub extern "C" fn my_fun(_x: MyType) {}
5075-
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5076-
/// |
5077-
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5078-
/// = note: for more information, see issue #138762 <https://github.com/rust-lang/rust/issues/138762>
5079-
/// = help: the "C" ABI Rust uses on wasm32-unknown-unknown will change to align with the standard "C" ABI for this target
5073+
/// --> $DIR/wasm_c_abi_transition.rs:17:1
5074+
/// |
5075+
/// | pub extern "C" fn my_fun(_x: MyType) {}
5076+
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5077+
/// |
5078+
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5079+
/// = note: for more information, see issue #138762 <https://github.com/rust-lang/rust/issues/138762>
5080+
/// = help: the "C" ABI Rust uses on wasm32-unknown-unknown will change to align with the standard "C" ABI for this target
50805081
/// ```
50815082
///
50825083
/// ### Explanation
@@ -5093,3 +5094,44 @@ declare_lint! {
50935094
reference: "issue #138762 <https://github.com/rust-lang/rust/issues/138762>",
50945095
};
50955096
}
5097+
5098+
declare_lint! {
5099+
/// The `aarch64_softfloat_neon` lint detects usage of `#[target_feature(enable = "neon")]` on
5100+
/// softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of
5101+
/// function calls, making this attribute unsound to use.
5102+
///
5103+
/// ### Example
5104+
///
5105+
/// ```rust,ignore (needs aarch64-unknown-none-softfloat)
5106+
/// #[target_feature(enable = "neon")]
5107+
/// fn with_neon() {}
5108+
/// ```
5109+
///
5110+
/// This will produce:
5111+
///
5112+
/// ```text
5113+
/// error: enabling the `neon` target feature on the current target is unsound due to ABI issues
5114+
/// --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18
5115+
/// |
5116+
/// | #[target_feature(enable = "neon")]
5117+
/// | ^^^^^^^^^^^^^^^
5118+
/// |
5119+
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5120+
/// = note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>
5121+
/// ```
5122+
///
5123+
/// ### Explanation
5124+
///
5125+
/// If a function like `with_neon` above ends up containing calls to LLVM builtins, those will
5126+
/// not use the correct ABI. This is caused by a lack of support in LLVM for mixing code with
5127+
/// and without the `neon` target feature. The target feature should never have been stabilized
5128+
/// on this target due to this issue, but the problem was not known at the time of
5129+
/// stabilization.
5130+
pub AARCH64_SOFTFLOAT_NEON,
5131+
Warn,
5132+
"detects code that could be affected by ABI issues on aarch64 softfloat targets",
5133+
@future_incompatible = FutureIncompatibleInfo {
5134+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
5135+
reference: "issue #134375 <https://github.com/rust-lang/rust/issues/134375>",
5136+
};
5137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ compile-flags: --crate-type=lib
2+
//@ compile-flags: --target=aarch64-unknown-none-softfloat
3+
//@ needs-llvm-components: aarch64
4+
#![feature(no_core, lang_items)]
5+
#![no_core]
6+
#![deny(aarch64_softfloat_neon)]
7+
8+
#[lang = "sized"]
9+
pub trait Sized {}
10+
11+
#[target_feature(enable = "neon")]
12+
//~^ERROR: enabling the `neon` target feature on the current target is unsound
13+
//~|WARN: previously accepted
14+
pub unsafe fn my_fun() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: enabling the `neon` target feature on the current target is unsound due to ABI issues
2+
--> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18
3+
|
4+
LL | #[target_feature(enable = "neon")]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>
9+
note: the lint level is defined here
10+
--> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:6:9
11+
|
12+
LL | #![deny(aarch64_softfloat_neon)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
Future incompatibility report: Future breakage diagnostic:
18+
error: enabling the `neon` target feature on the current target is unsound due to ABI issues
19+
--> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18
20+
|
21+
LL | #[target_feature(enable = "neon")]
22+
| ^^^^^^^^^^^^^^^
23+
|
24+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
25+
= note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>
26+
note: the lint level is defined here
27+
--> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:6:9
28+
|
29+
LL | #![deny(aarch64_softfloat_neon)]
30+
| ^^^^^^^^^^^^^^^^^^^^^^
31+

0 commit comments

Comments
 (0)