https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82608
Bug ID: 82608 Summary: missing -Warray-bounds on an out-of-bounds VLA index 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: --- GCC doesn't diagnose out-of-bounds indices into VLAs even in cases where it could. For instance, in the program below the upper bound of the VLA is at most 32 while the index is greater. This information is available in the VRP pass and so it should be possible to detect this bug. $ cat a.c && gcc -O2 -S -Wall -Warray-bounds -Wextra a.c void sink (void*); int f (unsigned n) { if (n < 1 || n > 32) n = 32; char vla[n]; sink (vla); return vla[97]; // missing -Warray-bounds }