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

            Bug ID: 78918
           Summary: missing -Wrestrict on memcpy copying over self
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Calling memcpy to copy objects that overlap violates the strict aliasing rules
and is undefined.  As the dump below shows, GCC eliminates some such calls
implying it "knows" the objects overlap (even though optimizing undefined code
seems questionable) but it doesn't issue any diagnostic.  With the -Wrestrict
warning GCC should flag at least the basic cases.

$ cat z.c && gcc -O2 -S -Wall -Wextra -Wpedantic -Wrestrict
-fdump-tree-optimized=/dev/stdout z.c
void f (void *p, void *q, unsigned n)
{
  p = q;
  __builtin_memcpy (p, q, n);
}

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

f (void * p, void * q, unsigned int n)
{
  <bb 2> [100.00%]:
  return;

}

Reply via email to