In some circumstances gcc 4.3.1 and later give the above warning incorrectly. I have tried this with:
gcc (Debian 4.3.1-2) 4.3.1 on x86_64 (This is the compiler in current Debian unstable) gcc (GCC) 4.4.0 20080624 (experimental) [trunk revision 137057] on PowerPC - this was built with "--disable-bootstrap --enable-languages=c") The .i version of my test program is as follows: # 1 "arrtest.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "arrtest.c" struct pt_regs { unsigned long gpr[32]; unsigned long nip; unsigned long msr; unsigned long orig_gpr3; unsigned long ctr; unsigned long link; unsigned long xer; unsigned long ccr; unsigned long softe; unsigned long trap; unsigned long dar; unsigned long dsisr; unsigned long result; }; void restore_sigcontext(struct pt_regs *regs) { unsigned long *gregs = (unsigned long *)regs; int i; for (i = 31; i <= 43; i++) gregs[i] = 1; for (i = 32; i <= 43; i++) gregs[i] = 1; for (i = 31; i <= 60; i++) gregs[i] = 1; } I compiled this with "gcc -Wall -O2 -c arrtest.c" and get the warning for the seond "gregs[i] = 1;" but not either of the others. This is a cut down from a file in the current Linux kernel PowerPC arch code. Compiler output: arrtest.c: In function ârestore_sigcontextâ: arrtest.c:29: warning: array subscript is above array bounds -- Summary: incorrect "warning: array subscript is above array bounds" Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gnu at rothwell dot id dot au http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36614