public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Jiangning Liu" <jiangning.liu@arm.com>
To: <gcc@gcc.gnu.org>
Cc: <jakub@gcc.gnu.org>,	<mueller@gcc.gnu.org>,	<rguenth@gcc.gnu.org>,
	"Matthew Gretton-Dann" <Matthew.Gretton-Dann@arm.com>
Subject: A question about detecting array bounds for case Warray-bounds-3.c
Date: Thu, 22 Sep 2011 02:19:00 -0000	[thread overview]
Message-ID: <000201cc78cd$f5a609f0$e0f21dd0$@liu@arm.com> (raw)

Hi,

For case gcc/testsuite/gcc.dg/Warray-bounds-3.c, obviously it is an invalid
C program, because the last iterations of all the loops cause the access of
arrays is beyond the max size of corresponding array declarations. The
condition of checking upper bound should be "<" rather than "<=". 

Right now, GCC compiler doesn't report any warning messages for this case,
should it be a bug in both test case and compiler?

But looking at http://gcc.gnu.org/PR31227 , it seems this test case is
designed to be like this on purpose. Anybody can explain about this?

The case is like below,

/* { dg-do compile } */
/* { dg-options "-O2 -Warray-bounds" } */
/* based on PR 31227 */

struct S
{
  const char *abday[7];
  const char *day[7];
  const char *abmon[12];
  const char *mon[12];
  const char *am_pm[2];
};

...

  for (cnt = 0; cnt <= 7; ++cnt)
    {
      iov[2 + cnt].iov_base = (void *) (time->abday[cnt] ?: "");
      iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
    }

  for (; cnt <= 14; ++cnt)
    {
      iov[2 + cnt].iov_base = (void *) (time->day[cnt - 7] ?: "");
      iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
    }

  for (; cnt <= 26; ++cnt)
    {
      iov[2 + cnt].iov_base = (void *) (time->abmon[cnt - 14] ?: "");
      iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
    }

  for (; cnt <= 38; ++cnt)
    {
      iov[2 + cnt].iov_base = (void *) (time->mon[cnt - 26] ?: "");
      iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
    }

  for (; cnt <= 40; ++cnt)
    {
      iov[2 + cnt].iov_base =  (void *) (time->am_pm[cnt - 38] ?: "");
      iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
    }

Thanks,
-Jiangning



             reply	other threads:[~2011-09-22  2:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22  2:19 Jiangning Liu [this message]
2011-09-26  8:32 Jiangning Liu
     [not found] <4e80264f.6ab8ec0a.78ce.ffffad1cSMTPIN_ADDED@mx.google.com>
2011-09-26  9:35 ` Jonathan Wakely
2011-09-26 11:01   ` Matthew Gretton-Dann
2011-09-28 13:52     ` Dirk Müller

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='000201cc78cd$f5a609f0$e0f21dd0$@liu@arm.com' \
    --to=jiangning.liu@arm.com \
    --cc=Matthew.Gretton-Dann@arm.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jakub@gcc.gnu.org \
    --cc=mueller@gcc.gnu.org \
    --cc=rguenth@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).