diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index f98f161e80938..4bee120db8c35 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -315,13 +315,18 @@ fn arg_attrs_for_rust_scalar<'tcx>( attrs.pointee_align = Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment())); - // `Box` are not necessarily dereferenceable for the entire duration of the function as - // they can be deallocated at any time. Same for non-frozen shared references (see - // ), and for mutable references to - // potentially self-referential types (see - // ). If LLVM had a way - // to say "dereferenceable on entry" we could use it here. attrs.pointee_size = match kind { + // LLVM dereferenceable attribute has unclear semantics on the return type, + // they seem to be "dereferenceable until the end of the program", which is + // generally, not valid for references. See + // + _ if is_return => Size::ZERO, + // `Box` are not necessarily dereferenceable for the entire duration of the function as + // they can be deallocated at any time. Same for non-frozen shared references (see + // ), and for mutable references to + // potentially self-referential types (see + // ). If LLVM had a way + // to say "dereferenceable on entry" we could use it here. PointerKind::Box { .. } | PointerKind::SharedRef { frozen: false } | PointerKind::MutableRef { unpin: false } => Size::ZERO, diff --git a/tests/codegen-llvm/function-arguments.rs b/tests/codegen-llvm/function-arguments.rs index 953b654555d53..4d557470504e0 100644 --- a/tests/codegen-llvm/function-arguments.rs +++ b/tests/codegen-llvm/function-arguments.rs @@ -85,7 +85,7 @@ pub fn option_nonzero_int(x: Option>) -> Option> { #[no_mangle] pub fn readonly_borrow(_: &i32) {} -// CHECK: noundef align 4 dereferenceable(4) ptr @readonly_borrow_ret() +// CHECK: noundef nonnull align 4 ptr @readonly_borrow_ret() #[no_mangle] pub fn readonly_borrow_ret() -> &'static i32 { loop {} @@ -116,7 +116,7 @@ pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {} #[no_mangle] pub fn mutable_borrow(_: &mut i32) {} -// CHECK: noundef align 4 dereferenceable(4) ptr @mutable_borrow_ret() +// CHECK: noundef nonnull align 4 ptr @mutable_borrow_ret() #[no_mangle] pub fn mutable_borrow_ret() -> &'static mut i32 { loop {}