+/* The recursive part of split_nonconstant_init. DEST is an lvalue
+ expression to which INIT should be assigned. INIT is a CONSTRUCTOR. */
+
+static void
+split_nonconstant_init_1 (tree dest, tree init)
+{
+ unsigned HOST_WIDE_INT idx;
+ tree field_index, value;
+ tree type = TREE_TYPE (dest);
+ tree inner_type = NULL;
+ bool array_type_p = false;
+
+ switch (TREE_CODE (type))
+ {
+ case ARRAY_TYPE:
+ inner_type = TREE_TYPE (type);
+ array_type_p = true;
+ /* FALLTHRU */
+
+ case RECORD_TYPE:
+ case UNION_TYPE:
+ case QUAL_UNION_TYPE:
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), idx,
+ field_index, value)
+ {
+ /* The current implementation of this algorithm assumes that
+ the field was set for all the elements. This is usually done
+ by process_init_constructor. */
+ gcc_assert (field_index);
+
+ if (!array_type_p)
+ inner_type = TREE_TYPE (field_index);
+
+ if (TREE_CODE (value) == CONSTRUCTOR)
+ {
+ tree sub;
+
+ if (array_type_p)
+ sub = build4 (ARRAY_REF, inner_type, dest, field_index,
+ NULL_TREE, NULL_TREE);
+ else
+ sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
+ NULL_TREE);
+
+ split_nonconstant_init_1 (sub, value);
+ }
+ else if (!initializer_constant_valid_p (value, inner_type))
+ {
+ tree code;
+ tree sub;
+
+ /* FIXME: Ordered removal is O(1) so the whole function is
+ worst-case quadratic. This could be fixed using an aside
+ bitmap to record which elements must be removed and remove
+ them all at the same time. Or by merging
+ split_non_constant_init into process_init_constructor_array,
+ that is separating constants from non-constants while building
+ the vector. */
+ VEC_ordered_remove (constructor_elt, CONSTRUCTOR_ELTS (init),
+ idx);
+ --idx;
+
+ if (array_type_p)
+ sub = build4 (ARRAY_REF, inner_type, dest, field_index,
+ NULL_TREE, NULL_TREE);
+ else
+ sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
+ NULL_TREE);
+
+ code = build2 (INIT_EXPR, inner_type, sub, value);
+ code = build_stmt (EXPR_STMT, code);
+ add_stmt (code);
+ continue;
+ }
+ }
+ break;
+
+ case VECTOR_TYPE:
+ if (!initializer_constant_valid_p (init, type))
+ {
+ tree code;
+ tree cons = copy_node (init);
+ CONSTRUCTOR_ELTS (init) = NULL;
+ code = build2 (MODIFY_EXPR, type, dest, cons);
+ code = build_stmt (EXPR_STMT, code);
+ add_stmt (code);
+ }
+ break;
+
+ default:
+ gcc_unreachable ();
+ }
+
+ /* The rest of the initializer is now a constant. */
+ TREE_CONSTANT (init) = 1;
+}
+
+/* A subroutine of store_init_value. Splits non-constant static
+ initializer INIT into a constant part and generates code to
+ perform the non-constant part of the initialization to DEST.
+ Returns the code for the runtime init. */
+
+static tree
+split_nonconstant_init (tree dest, tree init)
+{
+ tree code;
+
+ if (TREE_CODE (init) == CONSTRUCTOR)
+ {
+ code = push_stmt_list ();
+ split_nonconstant_init_1 (dest, init);
+ code = pop_stmt_list (code);
+ DECL_INITIAL (dest) = init;
+ TREE_READONLY (dest) = 0;
+ }
+ else
+ code = build2 (INIT_EXPR, TREE_TYPE (dest), dest, init);
+
+ return code;
+}
+