Bug ID: 84754
           Summary: missing -Wrestrict on a possible strcpy overlap with
                    constant offset
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot
          Reporter: msebor at gcc dot
  Target Milestone: ---

-Wrestrict triggers for a strcpy call from a string of unknown length and
unknown offset but not the same call with a constant offset, even though the
latter seems more likely to overlap than the former (the smaller the offset the
more likely the cooy is to overlap).  In any case, unlike for memcpy, for
string functions -Wrestrict is specifically meant to warn even for possible
overlaps (i.e., when copying into the same array) so this is a bug, not just a
missing feature or design choice.

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

void f (int i)
  __builtin_strcpy (a, a + i);   // -Wrestrict (good)

void g (void)
  __builtin_strcpy (a, a + 1);   // missing -Wrestrict

;; Function f (f, funcdef_no=0, decl_uid=1959, cgraph_uid=0, symbol_order=1)

z.c: In function ‘f’:
z.c:5:3: warning: ‘__builtin_strcpy’ accessing 1 byte at offsets 0 and [0, 32]
may overlap 1 byte at offset 0 [-Wrestrict]
   __builtin_strcpy (a, a + i);   // -Wrestrict (good)
f (int i)
  sizetype _1;
  const char * _2;

  <bb 2> [local count: 1073741825]:
  _1 = (sizetype) i_3(D);
  _2 = &a + _1;
  __builtin_strcpy (&a, _2);


;; Function g (g, funcdef_no=1, decl_uid=1962, cgraph_uid=1, symbol_order=2)

g ()
  <bb 2> [local count: 1073741825]:
  __builtin_strcpy (&a, &MEM[(void *)&a + 1B]);


Reply via email to