This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix middle-end/81737
- From: Marek Polacek <polacek at redhat dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Jakub Jelinek <jakub at redhat dot com>
- Date: Tue, 8 Aug 2017 19:23:45 +0200
- Subject: Re: [PATCH] Fix middle-end/81737
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=polacek at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E0E394E4CA
- References: <20170807084751.GC17069@redhat.com> <20170807085809.GJ2123@tucnak> <20170807090959.GD17069@redhat.com> <FD4948E3-CE8A-45FC-BC2D-FA556B460BF4@gmail.com>
On Mon, Aug 07, 2017 at 04:07:49PM +0200, Richard Biener wrote:
> On August 7, 2017 11:09:59 AM GMT+02:00, Marek Polacek <polacek@redhat.com> wrote:
> >On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote:
> >> 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.
>
> It's how the middle-end defines it, so please restore this behavior (sorry for missing this in the review). IIRC there are at least one other 'copy' of the folding somewhere.
Sure, this patch should do it:
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-08-08 Marek Polacek <polacek@redhat.com>
PR middle/81695
* fold-const.c (fold_indirect_ref_1): Restore original behavior
regarding size_zero_node.
diff --git gcc/fold-const.c gcc/fold-const.c
index 5a118ca50a1..2c47d1d16a4 100644
--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -14109,22 +14109,21 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
&& type == TREE_TYPE (op00type))
{
tree type_domain = TYPE_DOMAIN (op00type);
- tree min;
+ tree min = size_zero_node;
if (type_domain != NULL_TREE
- && (min = TYPE_MIN_VALUE (type_domain))
+ && TYPE_MIN_VALUE (type_domain)
&& TREE_CODE (min) == INTEGER_CST)
+ min = TYPE_MIN_VALUE (type_domain);
+ offset_int off = wi::to_offset (op01);
+ offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
+ offset_int remainder;
+ off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
+ if (remainder == 0)
{
- offset_int off = wi::to_offset (op01);
- offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
- offset_int remainder;
- off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
- if (remainder == 0)
- {
- off = off + wi::to_offset (min);
- op01 = wide_int_to_tree (sizetype, off);
- return build4_loc (loc, ARRAY_REF, type, op00, op01,
- NULL_TREE, NULL_TREE);
- }
+ off = off + wi::to_offset (min);
+ op01 = wide_int_to_tree (sizetype, off);
+ return build4_loc (loc, ARRAY_REF, type, op00, op01,
+ NULL_TREE, NULL_TREE);
}
}
}
Marek