https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86196
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Known to work| |8.1.0 Keywords| |diagnostic Last reconfirmed| |2018-06-18 CC| |msebor at gcc dot gnu.org Blocks| |84774 Ever confirmed|0 |1 Summary|Bogus -Wrestrict on memcpy |[9 Regression] Bogus | |-Wrestrict on memcpy | |between array elements at | |unequal indices Known to fail| |9.0 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed with the simplified test case below. The "offset [0, 8]" notation indicates the range the offset into an array is determined to be in. The bug is caused by GCC incorrectly computing the offset to be between 0 and 8 bytes (the 8 is the size of the struct). $ cat pr86196.c && gcc -O2 -S -Wall pr86196.c struct S { int i; void *p; }; void g (struct S *a, int i, int j) { if (i != j) __builtin_memcpy (&a[j], &a[i], sizeof (struct S)); } pr86196.c: In function ‘g’: pr86196.c:6:5: warning: ‘__builtin_memcpy’ accessing 16 bytes at offsets [0, 8] and [0, 8] overlaps between 8 and 16 bytes at offset [0, 8] [-Wrestrict] __builtin_memcpy (&a[j], &a[i], sizeof (struct S)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The regression was introduced in r260280: r260280 | msebor | 2018-05-15 22:30:38 -0400 (Tue, 15 May 2018) | 15 lines PR tree-optimization/85753 - missing -Wrestrict on memcpy into a member array gcc/ChangeLog: PR tree-optimization/85753 * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Handle RECORD_TYPE in addition to ARRAY_TYPE. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84774 [Bug 84774] [meta-bug] bogus/missing -Wrestrict