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

            Bug ID: 86196
           Summary: Bogus -Wrestrict on memcpy
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

With recent trunk (on Linux x86_64), and doesn't seem to be covered by existing
bugs referenced from meta bug 84774:

> $ gcc --version
> gcc (GCC) 9.0.0 20180618 (experimental)
> Copyright (C) 2018 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> $ cat test.c
> #include <string.h>
> struct S {
>     int n;
>     void * p;
> };
> void f(struct S * a, size_t n) {
>     size_t i = 0, j = 0;
>     for (; i != n; ++i) {
>         if (a[i].n == 0) {
>             if (i != j) {
>                 memcpy(&a[j], &a[i], sizeof (struct S));
>             }
>             ++j;
>         }
>     }
> }

> $ gcc -Wall -c test.c
> test.c: In function ‘f’:
> test.c:11:17: warning: ‘memcpy’ accessing 16 bytes at offsets [0, 8] and [0, 
> 8] overlaps between 8 and 16 bytes at offset [0, 8] [-Wrestrict]
>                  memcpy(&a[j], &a[i], sizeof (struct S));
>                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Also, I do not understand what that "offset [0, 8]" notation is supposed to
mean.

Reply via email to