You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #156242 - Jamesbarford:feat/remove-alwaysinline+target-feature, r=RalfJung,saethlin
Remove unsound `target_feature_inline_always` feature
## Summary
- Remove `target_feature_inline_always`
- Update stdarch generators to only use `#[inline]` & regenerate stdarch.
## Why?
Succinctly; the feature relies on LLVMs `AlwaysInlinerPass()` running before LLVMs heuristic based inliner pass. Which is not a basis for sound code.
This has been discussed in [the tracking issue](#145574).
If the ordering of the passes were to change, of which they have in the past, it is very possible we could inline functions across callsites with mismatching target features leading to unsound code. Checks proposed in; #155426 would only take into account caller -> callee which is not enough to guard against possibly of generating unsound code if the pass ordering were to change.
There doesn't seem to be a way, presently, this this mechanism to provide soundness guarantees nor does it seem like `AlwaysInlinerPass()` is a desired feature of LLVM, which this feature relies on.
r? @RalfJung
Copy file name to clipboardExpand all lines: compiler/rustc_lint_defs/src/builtin.rs
-56Lines changed: 0 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,6 @@ declare_lint_pass! {
56
56
ILL_FORMED_ATTRIBUTE_INPUT,
57
57
INCOMPLETE_INCLUDE,
58
58
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
59
-
INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
60
59
INLINE_NO_SANITIZE,
61
60
INVALID_DOC_ATTRIBUTES,
62
61
INVALID_MACRO_EXPORT_ARGUMENTS,
@@ -5492,61 +5491,6 @@ declare_lint! {
5492
5491
"detects tail calls of functions marked with `#[track_caller]`",
5493
5492
@feature_gate = explicit_tail_calls;
5494
5493
}
5495
-
declare_lint!{
5496
-
/// The `inline_always_mismatching_target_features` lint will trigger when a
5497
-
/// function with the `#[inline(always)]` and `#[target_feature(enable = "...")]`
5498
-
/// attributes is called and cannot be inlined due to missing target features in the caller.
5499
-
///
5500
-
/// ### Example
5501
-
///
5502
-
/// ```rust,ignore (fails on x86_64)
5503
-
/// #[inline(always)]
5504
-
/// #[target_feature(enable = "fp16")]
5505
-
/// unsafe fn callee() {
5506
-
/// // operations using fp16 types
5507
-
/// }
5508
-
///
5509
-
/// // Caller does not enable the required target feature
5510
-
/// fn caller() {
5511
-
/// unsafe { callee(); }
5512
-
/// }
5513
-
///
5514
-
/// fn main() {
5515
-
/// caller();
5516
-
/// }
5517
-
/// ```
5518
-
///
5519
-
/// This will produce:
5520
-
///
5521
-
/// ```text
5522
-
/// warning: call to `#[inline(always)]`-annotated `callee` requires the same target features. Function will not have `alwaysinline` attribute applied
5523
-
/// --> $DIR/builtin.rs:5192:14
5524
-
/// |
5525
-
/// 10 | unsafe { callee(); }
5526
-
/// | ^^^^^^^^
5527
-
/// |
5528
-
/// note: `fp16` target feature enabled in `callee` here but missing from `caller`
5529
-
/// --> $DIR/builtin.rs:5185:1
5530
-
/// |
5531
-
/// 3 | #[target_feature(enable = "fp16")]
5532
-
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5533
-
/// 4 | unsafe fn callee() {
5534
-
/// | ------------------
5535
-
/// = note: `#[warn(inline_always_mismatching_target_features)]` on by default
5536
-
/// warning: 1 warning emitted
5537
-
/// ```
5538
-
///
5539
-
/// ### Explanation
5540
-
///
5541
-
/// Inlining a function with a target feature attribute into a caller that
5542
-
/// lacks the corresponding target feature can lead to unsound behavior.
5543
-
/// LLVM may select the wrong instructions or registers, or reorder
5544
-
/// operations, potentially resulting in runtime errors.
5545
-
pubINLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
5546
-
Warn,
5547
-
r#"detects when a function annotated with `#[inline(always)]` and `#[target_feature(enable = "..")]` is inlined into a caller without the required target feature"#,
5548
-
}
5549
-
5550
5494
declare_lint!{
5551
5495
/// The `repr_c_enums_larger_than_int` lint detects `repr(C)` enums with discriminant
5552
5496
/// values that do not fit into a C `int` or `unsigned int`.
0 commit comments