https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92363
Bug ID: 92363 Summary: wrong subscript value printed when indexing into an empty array 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: --- The -Warray-bounds code takes a shortcut when it detects an access to an array whose lower bound is equal to its upper bound and prints the same warning message regardless of the subscript: /* Empty array. */ if (up_bound && tree_int_cst_equal (low_bound, up_bound_p1)) warned = warning_at (location, OPT_Warray_bounds, "array subscript %E is above array bounds of %qT", low_bound, artype); That can cause the message to mention the wrong subscript value such as in the test case below: $ cat b.c && gcc -O2 -S -Wall -Warray-bounds b.c int f (void) { int a[] = { }; return a[-1]; } b.c: In function ‘f’: b.c:4:11: warning: array subscript 0 is above array bounds of ‘int[0]’ [-Warray-bounds] 4 | return a[-1]; | ~^~~~ b.c:3:7: note: while referencing ‘a’ 3 | int a[] = { }; | ^