diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index d644cbccea1..73d2d278f93 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -273,9 +273,11 @@ fn adjust_for_rust_scalar<'tcx>( | PointerKind::UniqueBorrowed | PointerKind::UniqueBorrowedPinned => false, PointerKind::UniqueOwned => noalias_for_box, - PointerKind::Frozen => !is_return, + PointerKind::Frozen => true, }; - if no_alias { + // We can never add `noalias` in return position; that LLVM attribute has some very surprising semantics + // (see ). + if no_alias && !is_return { attrs.set(ArgAttribute::NoAlias); } diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs index 44fee952307..0f9e90f6ba7 100644 --- a/src/test/codegen/function-arguments.rs +++ b/src/test/codegen/function-arguments.rs @@ -145,7 +145,7 @@ pub fn raw_struct(_: *const S) { // `Box` can get deallocated during execution of the function, so it should // not get `dereferenceable`. -// CHECK: noalias noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x) +// CHECK: noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x) #[no_mangle] pub fn _box(x: Box) -> Box { x