public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: gcc-help@gcc.gnu.org
Subject: Re: False positive from -Warray-bounds?
Date: Fri, 30 Dec 2011 00:38:00 -0000	[thread overview]
Message-ID: <mcrehvm52qn.fsf@dhcp-172-18-216-180.mtv.corp.google.com> (raw)
In-Reply-To: <20111229235727.GU5641@xvii.vinc17.org> (Vincent Lefevre's	message of "Fri, 30 Dec 2011 00:57:27 +0100")

Vincent Lefevre <vincent+gcc@vinc17.org> writes:

> On 2011-12-29 15:24:08 -0800, Ian Lance Taylor wrote:
>> I guess it's a matter of perspective.  What that text is intended to say
>> is: the compiler can prove that the array access is out of bounds.
>
> ... based on an incorrect hypothesis (that the path can be reached).
> With an incorrect hypothesis, one can prove anything.

This is not logic.  It is compiler optimization.


> So, I don't
> think that would be a valid proof.
>
> For instance, compiling the following code with -O2 -Warray-bounds -c
> triggers the warning.
>
> 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)
> {
>   if (s >> 1 == 0)
>     {
>       arr1[f(s)] = 0;
>       arr1[f(s)] = 0;
>     }
> }

To me this only proves that the compiler is not smart enough to see that
(s >> 1 == 0) implies that ((s & 0xffff) == 0xffff) can not be true.

Are you suggesting that the compiler should never warn if there is a
conditional guarding the array access?  Would that in practice be better
or worse than the current behaviour?

Ian

  parent reply	other threads:[~2011-12-30  0:21 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 [this message]
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
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=mcrehvm52qn.fsf@dhcp-172-18-216-180.mtv.corp.google.com \
    --to=iant@google.com \
    --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).