https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106927
Bug ID: 106927 Summary: false-positive -Werror=restrict warnings for memmove (calling memcpy) within array Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gcc at boris dot fau.re Target Milestone: --- When compiling the following code with -Werror=restrict, gcc complains: $cat foo.c #include <string.h> int main (void) { char *s = "abcdefghijklmnopqrstuvwxyz012345"; size_t d = strlen(s); __builtin_memmove(s, s + 1, d - 1); return 0; } $ gcc -c -O2 -Werror=restrict -o foo.o foo.c foo.c: In function 'main': foo.c:8:5: error: '__builtin_memcpy' accessing 31 bytes at offsets 0 and 1 overlaps 30 bytes at offset 1 [-Werror=restrict] 8 | __builtin_memmove(s, s + 1, d - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This was reproduced on gentoo with gcc-11.3.0, on RHEL9 with gcc-11.2.1, on debian bullseye with gcc-12.2.0, on debian buster with gcc-9.5.0, RHEL8 with gcc-8.5.0. Please note that, on gcc-12.2.0, without -O2, the compilation succeeds.