Hi!

As the testcase shows, gimplification of the VECTOR_TYPE CONSTRUCTOR
elements can turn previously valid initializer_constant_valid_p
into a temporary (thus no longer initializer_constant_valid_p).

The following patch just clears TREE_STATIC on the ctor if that happens,
so that we expand it properly.

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

Or should we instead check initializer_constant_valid_p first and not
gimplify the initializer in that case if the ctor is TREE_STATIC?
I'm just afraid that the optimization passes would be upset to see
more complex elements in the initializers, and it is something people don't
really write in real-world anyway.

2016-04-12  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/70633
        * gimplify.c (gimplify_init_constructor): Clear TREE_STATIC if
        gimplification turns some element into non-constant.

        * gcc.c-torture/compile/pr70633.c: New test.

--- gcc/gimplify.c.jj   2016-04-09 13:21:09.000000000 +0200
+++ gcc/gimplify.c      2016-04-12 16:50:17.271533881 +0200
@@ -4164,7 +4164,7 @@ gimplify_init_constructor (tree *expr_p,
          }
 
        /* Vector types use CONSTRUCTOR all the way through gimple
-         compilation as a general initializer.  */
+          compilation as a general initializer.  */
        FOR_EACH_VEC_SAFE_ELT (elts, ix, ce)
          {
            enum gimplify_status tret;
@@ -4172,6 +4172,10 @@ gimplify_init_constructor (tree *expr_p,
                                  fb_rvalue);
            if (tret == GS_ERROR)
              ret = GS_ERROR;
+           else if (TREE_STATIC (ctor)
+                    && !initializer_constant_valid_p (ce->value,
+                                                      TREE_TYPE (ce->value)))
+             TREE_STATIC (ctor) = 0;
          }
        if (!is_gimple_reg (TREE_OPERAND (*expr_p, 0)))
          TREE_OPERAND (*expr_p, 1) = get_formal_tmp_var (ctor, pre_p);
--- gcc/testsuite/gcc.c-torture/compile/pr70633.c.jj    2016-04-12 
17:24:40.494491310 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr70633.c       2016-04-12 
17:24:23.000000000 +0200
@@ -0,0 +1,12 @@
+/* PR middle-end/70633 */
+
+typedef long V __attribute__((vector_size (4 * sizeof (long))));
+
+void foo (V *);
+
+void
+bar (void)
+{ 
+  V b = { (long) bar, 0, 0, 0 };
+  foo (&b);
+}

        Jakub

Reply via email to