[Bug middle-end/32667] block copy with exact overlap is expanded as memcpy

bugdal at aerifal dot cx gcc-bugzilla@gcc.gnu.org
Thu Nov 23 18:55:59 GMT 2023


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667

--- Comment #42 from Rich Felker <bugdal at aerifal dot cx> ---
> I'm not saying that such an implementation will be a good idea, but just a remark: You could, in fact, keep restrict for the arguments in this case, because the object pointed to by src and dest is not accessed at all when src==dest. So this is correct code according to the standard. (The exact semantics of restrict are a bit involved...)

Nope, UB is invoked as soon as you evaluate src==dest, even with no
dereferencing. The semantics of restrict are such that the behavior of the code
must be unchanged if the pointer were replaced to a pointer to a relocated copy
of the pointed-to object. Since this would alter the result of the == operator,
that constraint is not satisfied and thereby the behavior is undefined.


More information about the Gcc-bugs mailing list