Skip to content

Commit e726130

Browse files
committed
stop applying dereferenceable(n) to return types
1 parent ce63e5d commit e726130

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

‎compiler/rustc_ty_utils/src/abi.rs‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,18 @@ fn arg_attrs_for_rust_scalar<'tcx>(
315315
attrs.pointee_align =
316316
Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment()));
317317

318-
// `Box` are not necessarily dereferenceable for the entire duration of the function as
319-
// they can be deallocated at any time. Same for non-frozen shared references (see
320-
// <https://github.com/rust-lang/rust/pull/98017>), and for mutable references to
321-
// potentially self-referential types (see
322-
// <https://github.com/rust-lang/unsafe-code-guidelines/issues/381>). If LLVM had a way
323-
// to say "dereferenceable on entry" we could use it here.
324318
attrs.pointee_size = match kind {
319+
// LLVM dereferenceable attribute has unclear semantics on the return type,
320+
// they seem to be "dereferenceable until the end of the program", which is
321+
// generally, not valid for references. See
322+
// <https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/LLVM.20dereferenceable.20on.20return.20type/with/563001493>
323+
_ if is_return => Size::ZERO,
324+
// `Box` are not necessarily dereferenceable for the entire duration of the function as
325+
// they can be deallocated at any time. Same for non-frozen shared references (see
326+
// <https://github.com/rust-lang/rust/pull/98017>), and for mutable references to
327+
// potentially self-referential types (see
328+
// <https://github.com/rust-lang/unsafe-code-guidelines/issues/381>). If LLVM had a way
329+
// to say "dereferenceable on entry" we could use it here.
325330
PointerKind::Box { .. }
326331
| PointerKind::SharedRef { frozen: false }
327332
| PointerKind::MutableRef { unpin: false } => Size::ZERO,

‎tests/codegen-llvm/function-arguments.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn option_nonzero_int(x: Option<NonZero<u64>>) -> Option<NonZero<u64>> {
8585
#[no_mangle]
8686
pub fn readonly_borrow(_: &i32) {}
8787

88-
// CHECK: noundef align 4 dereferenceable(4) ptr @readonly_borrow_ret()
88+
// CHECK: noundef nonnull align 4 ptr @readonly_borrow_ret()
8989
#[no_mangle]
9090
pub fn readonly_borrow_ret() -> &'static i32 {
9191
loop {}
@@ -116,7 +116,7 @@ pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {}
116116
#[no_mangle]
117117
pub fn mutable_borrow(_: &mut i32) {}
118118

119-
// CHECK: noundef align 4 dereferenceable(4) ptr @mutable_borrow_ret()
119+
// CHECK: noundef nonnull align 4 ptr @mutable_borrow_ret()
120120
#[no_mangle]
121121
pub fn mutable_borrow_ret() -> &'static mut i32 {
122122
loop {}

0 commit comments

Comments
 (0)