@@ -3,6 +3,7 @@ use std::iter;
33use rustc_abi:: Primitive :: Pointer ;
44use rustc_abi:: { BackendRepr , ExternAbi , PointerKind , Scalar , Size } ;
55use rustc_hir as hir;
6+ use rustc_hir:: attrs:: InlineAttr ;
67use rustc_hir:: lang_items:: LangItem ;
78use rustc_middle:: bug;
89use rustc_middle:: query:: Providers ;
@@ -275,6 +276,7 @@ fn arg_attrs_for_rust_scalar<'tcx>(
275276 offset : Size ,
276277 is_return : bool ,
277278 drop_target_pointee : Option < Ty < ' tcx > > ,
279+ is_inline : bool ,
278280) -> ArgAttributes {
279281 let mut attrs = ArgAttributes :: new ( ) ;
280282
@@ -348,9 +350,10 @@ fn arg_attrs_for_rust_scalar<'tcx>(
348350 PointerKind :: MutableRef { unpin } => unpin && noalias_mut_ref,
349351 PointerKind :: Box { unpin, global } => unpin && global && noalias_for_box,
350352 } ;
353+
351354 // We can never add `noalias` in return position; that LLVM attribute has some very surprising semantics
352355 // (see <https://github.com/rust-lang/unsafe-code-guidelines/issues/385#issuecomment-1368055745>).
353- if no_alias && !is_return {
356+ if no_alias && !is_inline && ! is_return {
354357 attrs. set ( ArgAttribute :: NoAlias ) ;
355358 }
356359
@@ -509,6 +512,11 @@ fn fn_abi_new_uncached<'tcx>(
509512 extra_args
510513 } ;
511514
515+ let is_inline = determined_fn_def_id. is_some_and ( |def_id| {
516+ let inline_attrs = tcx. codegen_fn_attrs ( def_id) . inline ;
517+ inline_attrs == InlineAttr :: Always
518+ } ) ;
519+
512520 let is_drop_in_place = determined_fn_def_id. is_some_and ( |def_id| {
513521 tcx. is_lang_item ( def_id, LangItem :: DropInPlace )
514522 || tcx. is_lang_item ( def_id, LangItem :: AsyncDropInPlace )
@@ -535,7 +543,15 @@ fn fn_abi_new_uncached<'tcx>(
535543 } ;
536544
537545 let mut arg = ArgAbi :: new ( cx, layout, |layout, scalar, offset| {
538- arg_attrs_for_rust_scalar ( * cx, scalar, * layout, offset, is_return, drop_target_pointee)
546+ arg_attrs_for_rust_scalar (
547+ * cx,
548+ scalar,
549+ * layout,
550+ offset,
551+ is_return,
552+ drop_target_pointee,
553+ is_inline,
554+ )
539555 } ) ;
540556
541557 if arg. layout . is_zst ( ) {
0 commit comments