From: Richard Biener <richard.guenther@gmail.com>
To: Aldy Hernandez <aldyh@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
Martin Sebor <msebor@redhat.com>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PR tree-optimization/84047] missing -Warray-bounds on an out-of-bounds index
Date: Wed, 31 Jan 2018 11:43:00 -0000 [thread overview]
Message-ID: <CAFiYyc1mjj6bgTEgC0_Y1JeCa9K_ww2-=X2k4V47z+x=0djfqA@mail.gmail.com> (raw)
In-Reply-To: <9a52975c-c720-f42f-3564-7b69e361487d@redhat.com>
On Tue, Jan 30, 2018 at 11:11 PM, Aldy Hernandez <aldyh@redhat.com> wrote:
> Hi!
>
> [Note: Jakub has mentioned that missing -Warray-bounds regressions should be
> punted to GCC 9. I think this particular one is easy pickings, but if this
> and/or the rest of the -Warray-bounds regressions should be marked as GCC 9
> material, please let me know so we can adjust all relevant PRs.]
>
> This is a -Warray-bounds regression that happens because the IL now has an
> MEM_REF instead on ARRAY_REF.
>
> Previously we had an ARRAY_REF we could diagnose:
>
> D.2720_5 = "12345678"[1073741824];
>
> But now this is represented as:
>
> _1 = MEM[(const char *)"12345678" + 1073741824B];
>
> I think we can just allow check_array_bounds() to handle MEM_REF's and
> everything should just work.
>
> The attached patch fixes both regressions mentioned in the PR.
>
> Tested on x86-64 Linux.
>
> OK?
This doesn't look correct. You lump MEM_REF handling together with
ADDR_EXPR handling but for the above case you want to diagnose
_dereferences_ not address-taking.
For the dereference case you need to amend the ARRAY_REF case, for example
via
Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c (revision 257181)
+++ gcc/tree-vrp.c (working copy)
@@ -5012,6 +5012,13 @@ check_array_bounds (tree *tp, int *walk_
if (TREE_CODE (t) == ARRAY_REF)
vrp_prop->check_array_ref (location, t, false /*ignore_off_by_one*/);
+ else if (TREE_CODE (t) == MEM_REF
+ && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
+ && TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) == STRING_CST)
+ {
+ call factored part of check_array_ref passing in STRING_CST and offset
+ }
+
else if (TREE_CODE (t) == ADDR_EXPR)
{
vrp_prop->search_for_addr_array (t, location);
note your patch will fail to warn for "1"[1] because taking that
address is valid but not
dereferencing it.
Richard.
next prev parent reply other threads:[~2018-01-31 11:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-30 22:43 Aldy Hernandez
2018-01-30 23:37 ` Martin Sebor
2018-01-31 11:43 ` Richard Biener [this message]
2018-02-01 17:42 ` Aldy Hernandez
2018-02-08 10:38 ` Richard Biener
2018-02-08 20:45 ` Martin Sebor
2018-02-14 12:30 ` Richard Biener
2018-02-13 22:58 ` Jeff Law
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='CAFiYyc1mjj6bgTEgC0_Y1JeCa9K_ww2-=X2k4V47z+x=0djfqA@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=aldyh@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=msebor@redhat.com \
/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).