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



             Bug #: 55222

           Summary: weird unstable "array subscript is above array bounds"

                    warning

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: akim.demai...@gmail.com





The following piece of code is a reduced version of a parser generated by

Bison.  It triggers a new warning (which must be very recently added to 4.8, as

last week or so there were no such warning AFAICT).



One issue is that the warning looks like a certainty, "array subscript is above

array bounds", well, no it is not, and another is that if I remove the previous

line, which displays "yyi", then the warning disappears.  This is fishy (at

least to my eyes).





$ cat array.c

#include <stdio.h>



typedef unsigned char uint8;

typedef signed char int8;



/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */

static const uint8 yyr2[] =

{

       0,     2,     0

};



/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in

   YYRHS.  */

static const uint8 yyprhs[] =

{

       0,     0,     3

};



/* YYRHS -- A `-1'-separated list of the rules' RHS.  */

static const int8 yyrhs[] =

{

       4,     0,    -1,    -1

};



void

yy_reduce_print (int yyrule)

{

  int yyi;

  for (yyi = 0; yyi < yyr2[yyrule]; yyi++)

    {

      fprintf (stderr, "$%d = ", yyi);

      fprintf (stderr, "%d\n", yyrhs[yyprhs[yyrule] + yyi]);

    }

}

$ gcc-mp-4.8 -Wall -O3 array.c -c

array.c: In function 'yy_reduce_print':

array.c:32:37: warning: array subscript is above array bounds [-Warray-bounds]

       fprintf (stderr, "%d\n", yyrhs[yyprhs[yyrule] + yyi]);

                                     ^

$ gcc-mp-4.8 --version

gcc-mp-4.8 (MacPorts gcc48 4.8-20121028_0) 4.8.0 20121028 (experimental)

Copyright (C) 2012 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



$ gcc-mp-4.7 -Wall -O3 array.c -c

$ gcc-mp-4.7 --version

gcc-mp-4.7 (MacPorts gcc47 4.7.2_2) 4.7.2

Copyright (C) 2012 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



$

Reply via email to