From: Jakub Jelinek <jakub@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix middle-end/81737
Date: Mon, 07 Aug 2017 08:58:00 -0000 [thread overview]
Message-ID: <20170807085809.GJ2123@tucnak> (raw)
In-Reply-To: <20170807084751.GC17069@redhat.com>
On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
> In my recent change I failed to check whether the type domain
> of a type is non-NULL and this goof causes crashing on this
> testcase.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-08-07 Marek Polacek <polacek@redhat.com>
>
> PR middle-end/81737
> * fold-const.c (fold_indirect_ref_1): Check type_domain.
>
> * gcc.dg/pr81737.c: New test.
The old code was assuming size_zero_node if type_domain is NULL
or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed might
be wrong perhaps for Fortran or Ada.
Hopefully nothing will assume this has to be folded in these cases (mainly
thinking about C++ constexpr).
So ok.
> diff --git gcc/fold-const.c gcc/fold-const.c
> index d563ba76766..8eaea6cce3a 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -14107,8 +14107,10 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
> && type == TREE_TYPE (op00type))
> {
> tree type_domain = TYPE_DOMAIN (op00type);
> - tree min = TYPE_MIN_VALUE (type_domain);
> - if (min && TREE_CODE (min) == INTEGER_CST)
> + tree min;
> + if (type_domain != NULL_TREE
> + && (min = TYPE_MIN_VALUE (type_domain))
> + && TREE_CODE (min) == INTEGER_CST)
> {
> offset_int off = wi::to_offset (op01);
> offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
> diff --git gcc/testsuite/gcc.dg/pr81737.c gcc/testsuite/gcc.dg/pr81737.c
> index e69de29bb2d..493358956ef 100644
> --- gcc/testsuite/gcc.dg/pr81737.c
> +++ gcc/testsuite/gcc.dg/pr81737.c
> @@ -0,0 +1,6 @@
> +/* PR middle-end/81737 */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +extern int a[];
> +void fn1() { (a + 0)[1]; }
>
> Marek
Jakub
next prev parent reply other threads:[~2017-08-07 8:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-07 8:47 Marek Polacek
2017-08-07 8:58 ` Jakub Jelinek [this message]
2017-08-07 9:10 ` Marek Polacek
2017-08-07 14:07 ` Richard Biener
2017-08-08 17:23 ` Marek Polacek
2017-08-14 8:32 ` Richard Biener
2017-08-16 10:51 ` Marek Polacek
2017-08-16 13:38 ` Richard Biener
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=20170807085809.GJ2123@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@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).