From: Vincent Lefevre <vincent+gcc@vinc17.org>
To: gcc-help@gcc.gnu.org
Subject: Re: False positive from -Warray-bounds?
Date: Thu, 29 Dec 2011 23:24:00 -0000 [thread overview]
Message-ID: <20111229231714.GT5641@xvii.vinc17.org> (raw)
In-Reply-To: <mcr4nwj595c.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
On 2011-12-29 14:02:23 -0800, Ian Lance Taylor wrote:
> Lars Gullik Bjønnes <larsbj@gullik.org> writes:
>
> > I have this code:
> >
> > --------------
> > unsigned int f(unsigned int value)
> > {
> > unsigned int i = (value & 0xffff);
> > return (i == 0xffff ? 0xffffffff : i);
> > }
> >
> >
> > static int *arr1[10];
> >
> > void t(unsigned int s)
> > {
> > arr1[f(s)] = 0;
> > arr1[f(s)] = 0;
> > }
> > ------------------
[...]
> The warning triggers if there is some code path in which the index is
> provably out of bounds. That is true of this code. I don't think I
> would describe this as a false positive. I think it is a case where, as
> the -Wall documentation says, the code should be modified to avoid the
> warning.
The -Warray-bounds warning occurs with:
void t(unsigned int s)
{
arr1[f(s)] = 0;
arr1[f(s)] = 0;
}
but not with:
void t(unsigned int s)
{
arr1[f(s)] = 0;
}
If "The warning triggers if there is some code path in which the index
is provably out of bounds." is the intended behavior (assuming that
the warning phrasing isn't really correct), isn't this proof the same
one in both cases? Why this difference in the gcc behavior?
Tested with the -O2 -Warray-bounds -c options and:
gcc (Debian 4.6.2-9) 4.6.2
and
gcc-snapshot (Debian 20111210-1) 4.7.0 20111210 (experimental) [trunk revision 182188]
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)
next prev parent reply other threads:[~2011-12-29 23:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-29 22:02 Lars Gullik Bjønnes
2011-12-29 22:45 ` Ian Lance Taylor
2011-12-29 23:03 ` Lars Gullik Bjønnes
2011-12-29 23:57 ` Ian Lance Taylor
2011-12-30 0:16 ` Vincent Lefevre
2011-12-30 0:21 ` Vincent Lefevre
2011-12-30 0:38 ` Ian Lance Taylor
2011-12-30 5:00 ` Vincent Lefevre
2011-12-30 8:29 ` Ian Lance Taylor
2011-12-30 12:08 ` David Brown
2011-12-30 19:44 ` Vincent Lefevre
2011-12-29 23:24 ` Vincent Lefevre [this message]
2011-12-30 0:19 ` Ian Lance Taylor
2011-12-29 23:17 ` Vincent Lefevre
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=20111229231714.GT5641@xvii.vinc17.org \
--to=vincent+gcc@vinc17.org \
--cc=gcc-help@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).