This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/59124] [4.8/4.9/5 Regression] Wrong warnings "array subscript is above array bounds"


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124

Alexander Peslyak <solar-gcc at openwall dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |solar-gcc at openwall dot com

--- Comment #8 from Alexander Peslyak <solar-gcc at openwall dot com> ---
Here's another testcase:

$ gcc -S -Wall -O2 -funroll-loops testcase.c 
testcase.c: In function 'DES_std_set_key':
testcase.c:14:17: warning: array subscript is above array bounds
[-Warray-bounds]
   while (DES_key[i++]) k += 2;
                 ^

=============== 8< ===============
static int DES_KS_updates;
static char DES_key[16];

void DES_std_set_key(char *key)
{
        int i, j, k, l;

        j = key[0];
        for (k = i = 0; (l = DES_key[i]) && (j = key[i]); i++)
                ;

        if (!j) {
                j = i;
                while (DES_key[i++]) k += 2;
        }

        if (k < j && ++DES_KS_updates) {
        }

        DES_key[0] = key[0];
}
=============== >8 ===============

GCC 4.7.4 and below report no warning, 4.8.0 and 4.9.2 report the warning
above.  Either -O2 -funroll-loops or -O3 result in the warning; simple -O2 does
not.  While i++ could potentially run beyond the end of DES_key[], depending on
what's in DES_key[] and key[], this isn't the case in the program this snippet
is taken from (and simplified), whereas the warning definitively claims "is"
rather than "might be".

For comparison, Dmitry's first testcase (from this bug's description) results
in no warning with -O2 -funroll-loops (but does give the warning to me with
-O3, as reported by Dmitry), whereas his second testcase (from comment 2) also
reports the warning with -O2 -funroll-loops (but not with simple -O2).  I
tested this with 4.9.2.

I hope this is similar enough to add to this bug (same affected versions, one
of the two testcases also affected by -funroll-loops).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]