Patchwork Don't fold zero-sized elements (PR c/58346)

login
register
mail settings
Submitter Marek Polacek
Date Jan. 17, 2014, 1:37 p.m.
Message ID <20140117133750.GI8907@redhat.com>
Download mbox | patch
Permalink /patch/312067/
State New
Headers show

Comments

Marek Polacek - Jan. 17, 2014, 1:37 p.m.
This is the real fix for PR58346.  I'd say the easiest solution is
just not fold the zero-sized elements.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-01-17  Marek Polacek  <polacek@redhat.com>

	PR c/58346
	* gimple-fold.c (fold_array_ctor_reference): Don't fold if element
	size is zero.
testsuite/
	* gcc.dg/pr58346.c: New test.


	Marek
Richard Guenther - Jan. 17, 2014, 2:37 p.m.
On Fri, Jan 17, 2014 at 2:37 PM, Marek Polacek <polacek@redhat.com> wrote:
> This is the real fix for PR58346.  I'd say the easiest solution is
> just not fold the zero-sized elements.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2014-01-17  Marek Polacek  <polacek@redhat.com>
>
>         PR c/58346
>         * gimple-fold.c (fold_array_ctor_reference): Don't fold if element
>         size is zero.
> testsuite/
>         * gcc.dg/pr58346.c: New test.
>
> --- gcc/gimple-fold.c.mp2       2014-01-17 12:03:56.149446880 +0100
> +++ gcc/gimple-fold.c   2014-01-17 12:04:00.450462677 +0100
> @@ -2940,7 +2940,8 @@ fold_array_ctor_reference (tree type, tr
>       be larger than size of array element.  */
>    if (!TYPE_SIZE_UNIT (type)
>        || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
> -      || elt_size.slt (tree_to_double_int (TYPE_SIZE_UNIT (type))))
> +      || elt_size.slt (tree_to_double_int (TYPE_SIZE_UNIT (type)))
> +      || elt_size.is_zero ())
>      return NULL_TREE;
>
>    /* Compute the array index we look for.  */
> --- gcc/testsuite/gcc.dg/pr58346.c.mp2  2014-01-17 12:27:26.180127058 +0100
> +++ gcc/testsuite/gcc.dg/pr58346.c      2014-01-17 12:28:20.466332046 +0100
> @@ -0,0 +1,19 @@
> +/* PR tree-optimization/58346 */
> +/* { dg-do compile } */
> +/* { dg-options "-O" } */
> +
> +struct U {};
> +static struct U b[1] = { };
> +extern void bar (struct U);
> +
> +void
> +foo (void)
> +{
> +  bar (b[0]);
> +}
> +
> +void
> +baz (void)
> +{
> +  foo ();
> +}
>
>         Marek

Patch

--- gcc/gimple-fold.c.mp2	2014-01-17 12:03:56.149446880 +0100
+++ gcc/gimple-fold.c	2014-01-17 12:04:00.450462677 +0100
@@ -2940,7 +2940,8 @@  fold_array_ctor_reference (tree type, tr
      be larger than size of array element.  */
   if (!TYPE_SIZE_UNIT (type)
       || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
-      || elt_size.slt (tree_to_double_int (TYPE_SIZE_UNIT (type))))
+      || elt_size.slt (tree_to_double_int (TYPE_SIZE_UNIT (type)))
+      || elt_size.is_zero ())
     return NULL_TREE;
 
   /* Compute the array index we look for.  */
--- gcc/testsuite/gcc.dg/pr58346.c.mp2	2014-01-17 12:27:26.180127058 +0100
+++ gcc/testsuite/gcc.dg/pr58346.c	2014-01-17 12:28:20.466332046 +0100
@@ -0,0 +1,19 @@ 
+/* PR tree-optimization/58346 */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct U {};
+static struct U b[1] = { };
+extern void bar (struct U);
+
+void
+foo (void)
+{
+  bar (b[0]);
+}
+
+void
+baz (void)
+{
+  foo ();
+}