This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, PR 43066] Skip arrays with zero-size type elements in build_ref_for_offset
- From: Richard Guenther <rguenther at suse dot de>
- To: Martin Jambor <mjambor at suse dot cz>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 18 Feb 2010 14:41:40 +0100 (CET)
- Subject: Re: [PATCH, PR 43066] Skip arrays with zero-size type elements in build_ref_for_offset
- References: <20100218133828.GA32360@virgil.suse.cz>
On Thu, 18 Feb 2010, Martin Jambor wrote:
> Hi,
>
> the fix for PR 43066 below makes build_ref_for_offset ignore arrays
> with element types with zero size so that we don't get a division by
> zero exception. Originally I intended to disable scalarization of
> aggregates with such arrays but I reckon that there may be no accesses
> to such arrays and there were two bug reports complaining about this
> so I assume people actually sometimes do use such arrays and so it may
> be worth not to pesimize such code. That is of course the plan B if
> we encounter any problems with this solution.
>
> Bootstrapped and regression tested on x86_64-linux. OK for trunk?
Ok.
Thanks,
Richard.
> Thanks,
>
> Martin
>
>
> 2010-02-17 Martin Jambor <mjambor@suse.cz>
>
> PR tree-optimization/
> * tree-sra.c (build_ref_for_offset_1): Return false on encountering an
> array with zero-sized element type.
>
> * testsuite/gcc.c-torture/compile/pr43066.c: New test.
>
> Index: mine/gcc/testsuite/gcc.c-torture/compile/pr43066.c
> ===================================================================
> --- /dev/null
> +++ mine/gcc/testsuite/gcc.c-torture/compile/pr43066.c
> @@ -0,0 +1,14 @@
> +struct S {
> + struct { } empty[1];
> + int i;
> +};
> +
> +int foo(int i, ...)
> +{
> + struct S s;
> + __builtin_va_list va;
> + __builtin_va_start(va, i);
> + s = __builtin_va_arg(va, struct S);
> + __builtin_va_end(va);
> + return s.i;
> +}
> Index: mine/gcc/tree-sra.c
> ===================================================================
> --- mine.orig/gcc/tree-sra.c
> +++ mine/gcc/tree-sra.c
> @@ -1432,7 +1432,7 @@ build_ref_for_offset_1 (tree *res, tree
> el_size = tree_low_cst (tr_size, 1);
>
> minidx = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
> - if (TREE_CODE (minidx) != INTEGER_CST)
> + if (TREE_CODE (minidx) != INTEGER_CST || el_size == 0)
> return false;
> if (res)
> {
>
>
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex