public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "akim.demaille at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/55222] New: weird unstable "array subscript is above array bounds" warning
Date: Tue, 06 Nov 2012 13:20:00 -0000	[thread overview]
Message-ID: <bug-55222-4@http.gcc.gnu.org/bugzilla/> (raw)


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: unassigned@gcc.gnu.org
        ReportedBy: akim.demaille@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	other threads:[~2012-11-06 13:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-06 13:20 akim.demaille at gmail dot com [this message]
2012-12-09  3:15 ` [Bug tree-optimization/55222] [4.8 Regression] " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-55222-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).