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

            Bug ID: 85753
           Summary: missing -Wrestrict on memcpy into a member array
           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: ---

GCC 8 diagnoses only the first of the two equivalently overlapping calls to
memcpy in the test case below but not the second.  Both should be diagnosed.

$ cat u.c && gcc -O2 -S -Wall -fdump-tree-wrestrict=/dev/stdout u.c
char a[16];

struct { char a[16]; } x;

void f (int i, int j)
{
  __builtin_memcpy (&a[i], &a[j], 9);   // -Wrestrict (good)

  __builtin_memcpy (&x.a[i], &x.a[j], 9);   // missing -Wrestrict
}

;; Function f (f, funcdef_no=0, decl_uid=1961, cgraph_uid=0, symbol_order=2)

u.c: In function ‘f’:
u.c:7:3: warning: ‘__builtin_memcpy’ accessing 9 bytes at offsets [0, 16] and
[0, 16] overlaps between 2 and 9 bytes at offset [0, 7] [-Wrestrict]
   __builtin_memcpy (&a[i], &a[j], 9);   // -Wrestrict (good)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
f (int i, int j)
{
  char * _1;
  char * _2;
  char * _3;
  char * _4;
  sizetype _10;
  sizetype _11;

  <bb 2> [local count: 1073741825]:
  _10 = (sizetype) j_5(D);
  _1 = &a + _10;
  _11 = (sizetype) i_6(D);
  _2 = &a + _11;
  __builtin_memcpy (_2, _1, 9);
  _3 = &x + _10;
  _4 = &x + _11;
  __builtin_memcpy (_4, _3, 9);
  return;

}

Reply via email to