https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95463
Bug ID: 95463 Summary: missing -Warray-bounds caused by assuming unsigned integer wrapping Product: gcc Version: 10.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: --- GCC avoids issuing -Warray-bounds for indices whose range wraps around zero, such as in g() below. Since unsigned wraparound is unlikely intended, issuing a warning in these cases would be justified even if a subset of the cases is valid. $ cat x.c && gcc -O2 -S -Wall x.c char a[2]; void f (unsigned i) { if (i > 2) return; a[i + 2] = 0; // -Warray-bounds (good) } void g (unsigned i) { if (i < 2) return; a[i + 2] = 0; // missing -Warray-bounds } x.c: In function ‘f’: x.c:7:4: warning: array subscript 2 is above array bounds of ‘char[2]’ [-Warray-bounds] 7 | a[i + 2] = 0; // -Warray-bounds (good) | ~^~~~~~~ x.c:1:6: note: while referencing ‘a’ 1 | char a[2]; | ^