In the following code, foo() properly guards the expression 'p[-1]' with a test that p is a pointer to an element of a[] other than the first element. Yet, when gcc analyzes array subscripts, it raises a warning because foo() is used in a context where p points to the first element of b[]. Even if the compiler isn't sophisticated enough to optimize away the entire body of foo(), it should have enough information to determine that 'p[-1]' is valid in the context where it is used. Instead, it complains: x.c: In function ‘bar’: x.c:7: warning: array subscript is below array bounds ---------------------------------------- int a[10], b[10]; static inline void foo(int *p) { if (p > a && p < a + 10) { p[-1] = 0; } } void bar(void) { foo(b); } ---------------------------------------- % gcc -v -save-temps -c -O2 -Wall x.c Using built-in specs. Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.4 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.4 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux Thread model: posix gcc version 4.4.1 [gcc-4_4-branch revision 150839] (SUSE Linux) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wall' '-mtune=generic' /usr/lib64/gcc/x86_64-suse-linux/4.4/cc1 -E -quiet -v x.c -mtune=generic -Wall -O2 -fpch-preprocess -o x.i #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib64/gcc/x86_64-suse-linux/4.4/include /usr/lib64/gcc/x86_64-suse-linux/4.4/include-fixed /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wall' '-mtune=generic' /usr/lib64/gcc/x86_64-suse-linux/4.4/cc1 -fpreprocessed x.i -quiet -dumpbase x.c -mtune=generic -auxbase x -O2 -Wall -version -o x.s GNU C (SUSE Linux) version 4.4.1 [gcc-4_4-branch revision 150839] (x86_64-suse-linux) compiled by GNU C version 4.4.1 [gcc-4_4-branch revision 150839], GMP version 4.3.1, MPFR version 2.4.1-p5. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 7c58d9f1f1af203b4391f1c94895405a x.c: In function ‘bar’: x.c:7: warning: array subscript is below array bounds COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wall' '-mtune=generic' /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/bin/as -V -Qy -o x.o x.s GNU assembler version 2.19.51 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE 11.2) 2.19.51.20090527-10.26.4 COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.4/:/usr/lib64/gcc/x86_64-suse-linux/4.4/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.4/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/bin/ LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.4/:/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wall' '-mtune=generic' -- Summary: Spurious array subscript warning Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jmattson at vmware dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44300