@@ -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 ,
0 commit comments