From: Ralf Jung Date: Mon, 2 Jan 2023 14:11:19 +0000 (+0100) Subject: do not add noalias in return position X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=e7cad62257e5b0d59ca18515a522e90924177330;p=rust.git do not add noalias in return position --- 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