https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92290
Bug ID: 92290 Summary: Inconsistent -Warray-bounds warning Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: sirl at gcc dot gnu.org Target Milestone: --- Created attachment 47133 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47133&action=edit testcase The attached creduced testcases recently started to warn differently in trunk (9 and earlier don't warn) depending on variable signedness. But I believe the possible range of the loop counter values should be the same. int a, b; unsigned short t1 (void) { int j; unsigned short pu = 0; unsigned int p[6] = { 0 }; unsigned int v; for (j = 0; j < 1234; j++) { v = a; if (((v >> 16) & 7) > 0) { int i; b = p[0]; for (i = 0; i < 6 - (int) ((v >> 16) & 0x07); i++) p[i] = p[i + ((v >> 16) & 0x07)]; } pu >>= (int) ((v >> 16) & 0x07) * 2; } return pu; } Compiled with -O2 -Warray-bounds, GCC trunk@277601 warns like this: testcase.c: In function 't1': testcase.c:17:14: warning: array subscript 6 is above array bounds of 'unsigned int[6]' [\-Warray-bounds=\] 17 | p[i] = p[i + ((v >> 16) & 0x07)]; | ~^~~~~~~~~~~~~~~~~~~~~~~~ testcase.c:7:16: note: while referencing ?p? 7 | unsigned int p[6] = { 0 }; | ^ t2() is a slight modification with re-arranged loop condition and gives the same warning. t3() uses an unsigned loop variable and doesn't warn, which seems the correct behaviour to me.