User account creation filtered due to spam.

Bug 39757 - inconsistency in array bounds checking with -O3
Summary: inconsistency in array bounds checking with -O3
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-14 02:58 UTC by Petteri Kettunen
Modified: 2012-02-02 20:41 UTC (History)
2 users (show)

See Also:
Host: i686-linux-gnu
Target: i486-linux-gnu
Build: i486-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petteri Kettunen 2009-04-14 02:58:02 UTC
gcc version:

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1) 

system type: Linux debian 2.6.26-1-686 #1 SMP Fri Mar 13 18:08:45 UTC 2009 i686 GNU/Linux

command line:

gcc -DNO_LCMS -Wall -Werror -O3 -c -o dcraw.o dcraw.c

source files:

curl -O 'http://www.cybercom.net/~dcoffin/dcraw/dcraw.c'

description of the expected behavior:

Compiles without errors.

description of actual behavior:

cc1: warnings being treated as errors
dcraw.c: In function ‘adobe_coeff’:
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c: In function ‘parse_phase_one’:
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds

The inconsistency hcc1: warnings being treated as errors
dcraw.c: In function ‘adobe_coeff’:
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c:6493: error: array subscript is above array bounds
dcraw.c: In function ‘parse_phase_one’:
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds
dcraw.c:5751: error: array subscript is above array bounds


For one, the compiler considers it an issues that array cam_xyz[4][3] is accessed as cam_xyz[0][j], 0 <= j < 12. This issue is found with -O3 but not with -O2.

The inconsistency, which I see is a bug, is that romm_camm[3][3] which is accessed as romm_cam[0][i], i <= j < 9, does not raise an error even after the above two cases are fixed.
Comment 1 Andrew Pinski 2009-04-14 03:00:36 UTC
-O3 has extra inlining.
Comment 2 Manuel López-Ibáñez 2009-04-20 22:56:27 UTC
(In reply to comment #1)
> -O3 has extra inlining.
> 

 ~/trunk/146344/build/gcc/cc1 -DNO_LCMS -Wall -Werror -O3 dcraw.i -fno-inline-functions -fno-inline

Still the same warnings. So, it seems to be some other reason.
Comment 3 Manuel López-Ibáñez 2009-08-05 10:01:01 UTC
By the way, we would prefer a preprocessed testcase, as minimal as possible. 
See http://gcc.gnu.org/bugs.html#report

Thanks.
Comment 4 Petteri Kettunen 2009-08-13 01:15:23 UTC
This is a bit odd but the bug was not reproducible when I tried to compile a minimal example in a file containing that function only. I shall investigate a bit more.
Comment 5 Andrew Pinski 2012-02-02 20:41:15 UTC
We have:
  short last[3] = { 16,16,16 }, mul[3], buf[3][3][386];
  for (i=0; i < sizeof(buf)/sizeof(short); i++)
    buf[0][0][i] = 2048;

Obviously this where one of the warning happens.

Likewise for:
  float cfilt=0, ddft[3][3][2], ppm[3][3][3];


>For one, the compiler considers it an issues that array cam_xyz[4][3] is
accessed as cam_xyz[0][j], 0 <= j < 12. This issue is found with -O3 but not
with -O2.

That warning is correct.  Now for the other part, this warning really depends on optimization and is not always 100% of producing all the warnings it could.