[Bug tree-optimization/53198] [4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays

Emmanuel.Thome at inria dot fr gcc-bugzilla@gcc.gnu.org
Mon Oct 14 10:14:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53198

Emmanuel Thomé <Emmanuel.Thome at inria dot fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Emmanuel.Thome at inria dot fr

--- Comment #7 from Emmanuel Thomé <Emmanuel.Thome at inria dot fr> ---

Hi,

Seems to me that the bug is still present in 4.7.3 (stock version,
x86_64-unknown-linux-gnu)

int foo(unsigned long t)        /* implicit promise that t != 0 */
{
    unsigned long a[2] = {0, t};
    int i;
    for(i = 1 ; !a[i] ; i++);
    return a[i];
}

int bar(unsigned long t)        /* implicit promise that t != 0 */
{
    unsigned long a[2] = {0, t};
    int i;
    for(i = 0 ; !a[++i] ; );
    return a[i];
}

$ gcc -c -W -Wall -O2 b.c
b.c: In function ‘foo’:
b.c:5:19: warning: array subscript is above array bounds [-Warray-bounds]


Interestingly, the two functions are equivalent as far as I can tell (sorry for
headaches induced by contrived control), and behave differently with 4.7.3.
Both with respect to the fact that only one triggers the warning, and also that
assembly code generated differs slightly.

4.8.1 behaves fine, and optimizes everything away as expected.


More information about the Gcc-bugs mailing list