Description
See https://reviews.llvm.org/D86993: LLVM, and therefore Rust, assume that memcpy
, memmove
, memset
and possibly other C standard library functions satisfy properties which are not required by the C standard. The least we can do is document this properly. However, I don't know where.
It's not just LLVM though, Rust itself also makes extra assumptions. We explicitly allow zero-sized accesses on pointers such as 42 as *const u8
, and this includes zero-sized copy_nonoverlapping
, copy
and write_bytes
. So basically we require zero-sized memcpy
, memmove
, memset
to be a NOP. (Technically it could still be UB for NULL, OOB, or UAF pointers, but we might want to change this on the Rust side and aside from NULL it's not really possibly for implementations to exploit that.) This is justified by us emitting LLVM operations that explicitly say size 0 is a NOP -- but I am not sure what other backends are doing.