https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86614
Bug ID: 86614 Summary: duplicate -Warray-bounds for a strncpy call with out-of-bounds offset Product: gcc Version: 9.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: --- With the recent enhancement to -Warray-bounds (bug 84047) GCC issues duplicate instances of the warning for calls to some built-in functions with out-of-bound offsets. The following test case was isolated from c-c++-common/Warray-bounds-2.c (r262906 prunes these duplicates from the test to avoid spurious failures). $ cat c.c && gcc -O2 -S -Warray-bounds c.c extern char* strncpy (char*, const char*, __SIZE_TYPE__); void sink (void*); struct { char b[17]; } a[2]; void g (const char *s, unsigned n) { int i = (char*)a[1].b - (char*)a + 1; char *d = a[1].b; strncpy (d + i, s, n); } c.c: In function ‘g’: c.c:11:3: warning: array subscript 35 is outside array bounds of ‘struct <anonymous>[2]’ [-Warray-bounds] strncpy (d + i, s, n); ^~~~~~~~~~~~~~~~~~~~~ c.c:11:3: warning: ‘strncpy’ offset 35 is out of the bounds [0, 34] of object ‘a’ with type ‘struct <anonymous>[2]’ [-Warray-bounds] c.c:5:24: note: ‘a’ declared here struct { char b[17]; } a[2]; ^