From e7cad62257e5b0d59ca18515a522e90924177330 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 2 Jan 2023 15:11:19 +0100 Subject: [PATCH] do not add noalias in return position --- compiler/rustc_ty_utils/src/abi.rs | 6 ++++-- src/test/codegen/function-arguments.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index d644cbccea11b..73d2d278f93f3 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 44fee952307f2..0f9e90f6ba779 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