https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84095
Bug ID: 84095
Summary: false-positive -Wrestrict warnings for memcpy within
array
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: arnd at linaro dot org
Target Milestone: ---
I see multiple new warnings for correct code in the Linux kernel for code that
copies one array member into other members of the same array, reduced to:
$ cat > test.c << EOF
struct { int i; } a[8];
void f(void)
{
int i;
for (i=1; i <8; i++)
__builtin_memcpy(&a[i], &a[0], sizeof(a[0]));
}
EOF
$ x86_64-linux-gcc-8.0.1 -c -Wall test.c
test4.c: In function 'f':
test4.c:8:3: warning: '__builtin_memcpy' accessing 4 bytes at offsets 0 and 0
overlaps 4 bytes at offset 0 [-Wrestrict]
__builtin_memcpy(&a[i], &a[0], sizeof(a[0]));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~