With -O3, I get an apparently incorrect "array subscript is above array bounds" warning when a multidimensional array is passed to a function and accessed in a loop: $ /home/tmp/u/rjpeters/gcc-svn-install/bin/gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: /home/tmp/u/rjpeters/gcc-svn/configure --enable-languages=c,c++ --enable-checking=yes --enable-__cxa_atexit --with-mpfr=/home/tmp/u/rjpeters/mpfr-2.2.1-install --with-gmp=/home/tmp/u/rjpeters/gmp-4.2.1-install --prefix=/home/tmp/u/rjpeters/gcc-svn-install Thread model: posix gcc version 4.4.0 20080220 (experimental) [trunk revision 129827] (GCC) $ cat bug2.c #include <stdio.h> static void test1(char f[][64], const int n) { int i; for (i = 0; i < n; ++i) printf("%s", f[i]); /* warning here */ printf("\n"); } static void test2(char f[][64]) { int i; for (i = 0; i < 4; ++i) printf("%s", f[i]); /* warning here */ printf("\n"); } static void test3(char f[][64]) { printf("%s", f[0]); printf("%s", f[1]); printf("%s", f[2]); printf("%s", f[3]); /* NOTE: no warning here */ printf("\n"); } int main() { char f[4][64] = { "a", "b", "c", "d" }; test1(f, 4); test2(f); test3(f); return 0; } $ /home/tmp/u/rjpeters/gcc-svn-install/bin/gcc -Wall -O3 bug2.c bug2.c: In function ‘main’: bug2.c:7: warning: array subscript is above array bounds bug2.c:7: warning: array subscript is above array bounds bug2.c:15: warning: array subscript is above array bounds bug2.c:15: warning: array subscript is above array bounds $ ./a.out abcd abcd abcd The fact that there are two warnings each at lines 7 and 14 suggests that somehow the last two iterations of the unrolled loop are considered as out-of-bounds; however, the generated code is apparently correct, at least judging by the runtime output of the program. I don't see these warnings with "gcc version 4.1.1 20060724 (prerelease) (4.1.1-3mdk)". Thanks, Rob
Created attachment 15197 [details] test case; compile with "-Wall -O3"
*** This bug has been marked as a duplicate of 37861 ***