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

--- Comment #17 from Martin Sebor <msebor at gcc dot gnu.org> ---
I've reduced the test case from comment #14 to the one below.  I'm inclined to
think the warning is justified.  As you say, the code clearly does use the same
pointer for both the source and the destination, so the code is strictly not
valid.  GCC ultimately eliminates the memcpy call and the whole loop, but not
before it notices the argument is the same.  The warning is issued in the same
places as the one for bug 83456 so if a decision is made to fix that bug this
warning will also disappear.

$ cat t.c && gcc -O2 -S -Wall t.c
extern void* memcpy (void*, const void*, __SIZE_TYPE__);

char a[4];

void f (unsigned n)
{
  for (int i = 0; i < 1; i++)
    {
      if (!i)
        continue;

      memcpy (a, a, n);
    }
}
t.c: In function ‘f’:
t.c:12:7: warning: ‘memcpy’ source argument is the same as destination
[-Wrestrict]
       memcpy (a, a, n);
       ^~~~~~~~~~~~~~~~

Reply via email to