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
Copy file name to clipboardExpand all lines: compiler/rustc_lint_defs/src/builtin.rs
+54Lines changed: 54 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5138,3 +5138,57 @@ declare_lint! {
5138
5138
"detects tail calls of functions marked with `#[track_caller]`",
5139
5139
@feature_gate = explicit_tail_calls;
5140
5140
}
5141
+
declare_lint!{
5142
+
/// The `inline_always_mismatching_target_features` lint will trigger when a
5143
+
/// function with the `#[inline(always)]` and `#[target_feature(enable = "...")]`
5144
+
/// attributes is called and cannot be inlined due to missing target features in the caller.
5145
+
///
5146
+
/// ### Example
5147
+
///
5148
+
/// ```rust,ignore (fails on x86_64)
5149
+
/// #[inline(always)]
5150
+
/// #[target_feature(enable = "fp16")]
5151
+
/// unsafe fn callee() {
5152
+
/// // operations using fp16 types
5153
+
/// }
5154
+
///
5155
+
/// // Caller does not enable the required target feature
5156
+
/// fn caller() {
5157
+
/// unsafe { callee(); }
5158
+
/// }
5159
+
///
5160
+
/// fn main() {
5161
+
/// caller();
5162
+
/// }
5163
+
/// ```
5164
+
///
5165
+
/// This will produce:
5166
+
///
5167
+
/// ```text
5168
+
/// warning: call to `#[inline(always)]`-annotated `callee` requires the same target features. Function will not have `alwaysinline` attribute applied
5169
+
/// --> $DIR/builtin.rs:5192:14
5170
+
/// |
5171
+
/// 10 | unsafe { callee(); }
5172
+
/// | ^^^^^^^^
5173
+
/// |
5174
+
/// note: `fp16` target feature enabled in `callee` here but missing from `caller`
5175
+
/// --> $DIR/builtin.rs:5185:1
5176
+
/// |
5177
+
/// 3 | #[target_feature(enable = "fp16")]
5178
+
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5179
+
/// 4 | unsafe fn callee() {
5180
+
/// | ------------------
5181
+
/// = note: `#[warn(inline_always_mismatching_target_features)]` on by default
5182
+
/// warning: 1 warning emitted
5183
+
/// ```
5184
+
///
5185
+
/// ### Explanation
5186
+
///
5187
+
/// Inlining a function with a target feature attribute into a caller that
5188
+
/// lacks the corresponding target feature can lead to unsound behavior.
5189
+
/// LLVM may select the wrong instructions or registers, or reorder
5190
+
/// operations, potentially resulting in runtime errors.
5191
+
pubINLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
5192
+
Warn,
5193
+
r#"detects when a function annotated with `#[inline(always)]` and `#[target_feature(enable = "..")]` is inlined into a caller without the required target feature"#,
0 commit comments