Skip to content

Commit 0381f59

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 d2acb42 commit 0381f59

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
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,
@@ -1428,14 +1428,18 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14281428
// Attributes on the function definition being called
14291429
let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id());
14301430
if let Some(fn_call_attrs) = fn_call_attrs
1431-
&& !fn_call_attrs.target_features.is_empty()
14321431
// If there is an inline attribute and a target feature that matches
14331432
// we will add the attribute to the callsite otherwise we'll omit
14341433
// this and not add the attribute to prevent soundness issues.
14351434
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, instance)
14361435
&& self.cx.tcx.is_target_feature_call_safe(
1437-
&fn_call_attrs.target_features,
14381436
&fn_defn_attrs.target_features,
1437+
&fn_call_attrs.target_features.iter().cloned().chain(
1438+
self.cx.tcx.sess.target_features.iter().map(|feat| TargetFeature {
1439+
name: *feat,
1440+
kind: TargetFeatureKind::Implied,
1441+
})
1442+
).collect::<Vec<_>>(),
14391443
)
14401444
{
14411445
attributes::apply_to_callsite(
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --target aarch64-unknown-linux-gnu -Zinline-mir=no -C no-prepopulate-passes
3+
//@ needs-llvm-components: aarch64
4+
5+
#![crate_type = "lib"]
6+
#![feature(no_core, lang_items, target_feature_inline_always)]
7+
#![no_core]
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
#[inline(always)]
13+
#[target_feature(enable = "neon")]
14+
#[no_mangle]
15+
pub fn single_target_feature() -> i32 {
16+
42
17+
}
18+
19+
#[inline(always)]
20+
#[target_feature(enable = "neon,i8mm")]
21+
#[no_mangle]
22+
// CHECK: define noundef i32 @multiple_target_features() unnamed_addr #1 {
23+
pub fn multiple_target_features() -> i32 {
24+
// CHECK: %_0 = call noundef i32 @single_target_feature() #3
25+
single_target_feature()
26+
}
27+
28+
#[no_mangle]
29+
// CHECK: define noundef i32 @inherits_from_global() unnamed_addr #2 {
30+
pub fn inherits_from_global() -> i32 {
31+
unsafe {
32+
// CHECK: %_0 = call noundef i32 @single_target_feature() #3
33+
single_target_feature()
34+
}
35+
}
36+
37+
// CHECK: attributes #3 = { alwaysinline nounwind }

0 commit comments

Comments
 (0)