This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, 4.5?] Fix get_ref_base_and_extent() handling of unions and variable sized arrays
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Guenther <rguenther at suse dot de>, Jan Hubicka <jh at suse dot cz>
- Date: Sat, 3 Jan 2009 14:38:16 +0100
- Subject: Re: [PATCH, 4.5?] Fix get_ref_base_and_extent() handling of unions and variable sized arrays
- References: <20081212181702.GD28354@virgil.suse.cz> <20081223115500.GA5383@virgil.suse.cz>
> Hi,
>
> On Fri, Dec 12, 2008 at 07:17:02PM +0100, Martin Jambor wrote:
> > Hi,
> >
> > this patch fixes bug in get_ref_base_and_extent() which makes it
> > return wrong max_size when dealing with variable size arrays within
> > unions.
> >
> > Please see discussion in the gcc mailing list, particularly the
> > following message for details:
> >
> > http://gcc.gnu.org/ml/gcc/2008-12/msg00192.html
> >
> > Even though this is technically a bug in trunk, I'm happy to postpone
> > this until 4.5. It may be part of the pretty-ipa branch sooner than
> > stage1.
> >
> > Bootstrapped and tested on x86_64.
> >
>
> I have now also bootstrapped and tested it against pretty-ipa branch.
> It is not ipa related per se but my current development on that branch
> requires the fix.
>
> Honza, can I commit it to the branch? (Alternatively, I can still
> keep it separate in my quilt patch set until Richi has a look at it
> but I do not want to intermingle it with the rest of the work).
In case I didn't OKed it already, it is OK :)
Honza
>
> Thanks,
>
> Martin
>
> >
> > 2008-12-12 Martin Jambor <mjambor@suse.cz>
> >
> > * tree-dfa.c (get_ref_base_and_extent): Return -1 maxsize if
> > seen_variable_array_ref while also traversing a union.
> >
> > Index: isra/gcc/tree-dfa.c
> > ===================================================================
> > --- isra.orig/gcc/tree-dfa.c
> > +++ isra/gcc/tree-dfa.c
> > @@ -797,6 +797,7 @@ get_ref_base_and_extent (tree exp, HOST_
> > tree size_tree = NULL_TREE;
> > HOST_WIDE_INT bit_offset = 0;
> > bool seen_variable_array_ref = false;
> > + bool seen_union = false;
> >
> > gcc_assert (!SSA_VAR_P (exp));
> >
> > @@ -840,6 +841,9 @@ get_ref_base_and_extent (tree exp, HOST_
> > tree field = TREE_OPERAND (exp, 1);
> > tree this_offset = component_ref_field_offset (exp);
> >
> > + if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == UNION_TYPE)
> > + seen_union = true;
> > +
> > if (this_offset && TREE_CODE (this_offset) == INTEGER_CST)
> > {
> > HOST_WIDE_INT hthis_offset = tree_low_cst (this_offset, 0);
> > @@ -930,12 +934,16 @@ get_ref_base_and_extent (tree exp, HOST_
> > where we do not know maxsize for variable index accesses to
> > the array. The simplest way to conservatively deal with this
> > is to punt in the case that offset + maxsize reaches the
> > - base type boundary. */
> > + base type boundary.
> > +
> > + Unfortunately this is difficult to determine reliably when unions are
> > + involved and so we are conservative in such cases. */
> > if (seen_variable_array_ref
> > - && maxsize != -1
> > - && host_integerp (TYPE_SIZE (TREE_TYPE (exp)), 1)
> > - && bit_offset + maxsize
> > - == (signed)TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp))))
> > + && (seen_union
> > + || (maxsize != -1
> > + && host_integerp (TYPE_SIZE (TREE_TYPE (exp)), 1)
> > + && bit_offset + maxsize
> > + == (signed) TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp))))))
> > maxsize = -1;
> >
> > /* ??? Due to negative offsets in ARRAY_REF we can end up with