Unnamed repository; edit this file 'description' to name the repository.
Rollup merge of #157560 - scottmcm:mul_nuw_nsw_in_memcpy, r=saethlin
In `copy_nonoverlapping`, use `mul nuw nsw` to compute the byte size Seems like we might as well? Adding these flags means the optimizer can tell the limited range on the count of items -- like how we use these flags (rust-lang/rust#136575) when calculating `size_of_val` for a slice. Today we use a wrapping multiplication, which mean that `copy_nonoverlapping::<u32>(src, dst, 0x40000000_00000001)` appears like 4 bytes -- a perfectly reasonable size! -- once it gets to the `memcpy` call. If I'm understanding <https://doc.rust-lang.org/std/ptr/fn.copy_nonoverlapping.html#safety> properly, this is just exploiting existing UB, since `src` and `dst` must each be inside an allocation, and those allocations can be at most `isize::MAX` bytes. (Plus, fundamentally, to be non-overlapping there's not enough space in the address space to be bigger than `isize::MAX`.) cc @RalfJung to make sure this is ok, as requested last he found out I was newly exploiting some UB in codegen 🙃 r? codegen
Jacob Pratt 5 weeks ago
parent 6922c2d · parent d62283f · commit 3540763
0 files changed, 0 insertions, 0 deletions