https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83456
Bug ID: 83456 Summary: -Wrestrict false positive on a non-overlapping memcpy in an inline function 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: --- As reported in bug 78918, comment #7, the enhanced -Wrestrict warning issues a false positive on the following code. The false positive is caused by issuing the warning during folding, after bar() has been inlined but before the call to memcpy has been eliminated. The reason for issuing the warning in this case (i.e., equal operands) is to help detect bugs in code built without optimization when an unguarded overlapping call to the library function would be made, but it may not be worth the bug reports for the safe cases like this one. $ cat z.c && gcc -O2 -S -Wall z.c extern void* memcpy (void*, const void*, __SIZE_TYPE__); inline void bar (void *d, void *s, unsigned N) { if (s != d) memcpy (d, s, N); } void foo (void* src) { bar (src, src, 1); } z.c: In function ‘foo’: z.c:6:5: warning: ‘memcpy’ source argument is the same as destination [-Wrestrict] memcpy (d, s, N); ^~~~~~~~~~~~~~~~