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

            Bug ID: 84793
           Summary: missig -Wrestrict accessing a struct and its first
                    member
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Wrestrict correctly complains when memcpy is called to copy from a struct into
itself, but it fails to trigger when the copy is between a struct and its
initial member.

$ cat z.c && gcc -O2 -S -Wall -Wextra -Wpedantic -Wrestrict z.c
extern void* memcpy (void* restrict, const void* restrict, __SIZE_TYPE__);

struct S {
  union {
    char a[4], b[4];
  };
} s;

void f (struct S *p, unsigned n)
{
  memcpy (p->a, p->b, n);   // -Wrestrict (good)
}

void g (struct S *p, unsigned n)
{
  memcpy (p, p->b, n);   // missing -Wrestrict
}


z.c: In function ‘f’:
z.c:11:3: warning: ‘memcpy’ source argument is the same as destination
[-Wrestrict]
   memcpy (p->a, p->b, n);   // -Wrestrict (good)
   ^~~~~~~~~~~~~~~~~~~~~~

Reply via email to