Skip to content

Commit 0a69024

Browse files
committed
Fix issue with callsite inline attribute not being applied sometimes.
If the calling function had more target features enabled than the callee than the attribute wasn't being applied as the arguments for the check had been swapped round. Also includes target features that are part of the global set as the warning was checking those but when adding the attribute they were not checked. Add a codegen-llvm test to check that the attribute is actually applied as previously only the warning was being checked.
1 parent d62e21f commit 0a69024

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_codegen_ssa::traits::*;
1717
use rustc_data_structures::small_c_str::SmallCStr;
1818
use rustc_hir::def_id::DefId;
1919
use rustc_middle::bug;
20-
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
20+
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature, TargetFeatureKind};
2121
use rustc_middle::ty::layout::{
2222
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers,
2323
TyAndLayout,
@@ -1419,14 +1419,18 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14191419
// Attributes on the function definition being called
14201420
let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id());
14211421
if let Some(fn_call_attrs) = fn_call_attrs
1422-
&& !fn_call_attrs.target_features.is_empty()
14231422
// If there is an inline attribute and a target feature that matches
14241423
// we will add the attribute to the callsite otherwise we'll omit
14251424
// this and not add the attribute to prevent soundness issues.
14261425
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, instance)
14271426
&& self.cx.tcx.is_target_feature_call_safe(
1428-
&fn_call_attrs.target_features,
14291427
&fn_defn_attrs.target_features,
1428+
&fn_call_attrs.target_features.iter().cloned().chain(
1429+
self.cx.tcx.sess.target_features.iter().map(|feat| TargetFeature {
1430+
name: *feat,
1431+
kind: TargetFeatureKind::Implied,
1432+
})
1433+
).collect::<Vec<_>>(),
14301434
)
14311435
{
14321436
attributes::apply_to_callsite(

tests/codegen-llvm/inline-always-callsite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ pub fn inherits_from_global() -> i32 {
3434
}
3535
}
3636

37-
// CHECK: attributes #3 = { nounwind }
37+
// CHECK: attributes #3 = { alwaysinline nounwind }

0 commit comments

Comments
 (0)