pub static INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES: &Lint
Expand description
The inline_always_mismatching_target_features
lint will trigger when a
function with the #[inline(always)]
and #[target_feature(enable = "...")]
attributes is called and cannot be inlined due to missing target features in the caller.
§Example
ⓘ
#[inline(always)]
#[target_feature(enable = "fp16")]
unsafe fn callee() {
// operations using fp16 types
}
// Caller does not enable the required target feature
fn caller() {
unsafe { callee(); }
}
fn main() {
caller();
}
This will produce:
warning: call to `#[inline(always)]`-annotated `callee` requires the same target features. Function will not have `alwaysinline` attribute applied
--> $DIR/builtin.rs:5192:14
|
10 | unsafe { callee(); }
| ^^^^^^^^
|
note: `fp16` target feature enabled in `callee` here but missing from `caller`
--> $DIR/builtin.rs:5185:1
|
3 | #[target_feature(enable = "fp16")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | unsafe fn callee() {
| ------------------
= note: `#[warn(inline_always_mismatching_target_features)]` on by default
warning: 1 warning emitted
§Explanation
Inlining a function with a target feature attribute into a caller that lacks the corresponding target feature can lead to unsound behavior. LLVM may select the wrong instructions or registers, or reorder operations, potentially resulting in runtime errors.