[PATCH] Don't fold zero-sized elements (PR c/58346)
Marek Polacek
polacek@redhat.com
Fri Jan 17 13:37:00 GMT 2014
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.
--- 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
More information about the Gcc-patches
mailing list