From b5ff0f707cec2415f4a87e76982e58909e45bbfe Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Sun, 23 Jan 1994 09:11:44 -0500 Subject: [PATCH] (output_init_elements): Use FIELD instead of constructor_fields when doing alignment and sizing. (output_init_elements): Use FIELD instead of constructor_fields when doing alignment and sizing. (output_pending_init_elements): Don't blow up when writing other than first field put haven't written anything yet. Update constructor_bit_index when we emit a skip. From-SVN: r6414 --- gcc/c-typeck.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 1e475d87e28..990c56f356a 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -5645,7 +5645,7 @@ output_init_element (value, type, field, pending) { /* Advance to offset of this element. */ if (! tree_int_cst_equal (constructor_bit_index, - DECL_FIELD_BITPOS (constructor_fields))) + DECL_FIELD_BITPOS (field))) { int next = (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)) / BITS_PER_UNIT); @@ -5663,9 +5663,8 @@ output_init_element (value, type, field, pending) if (TREE_CODE (constructor_type) == RECORD_TYPE || TREE_CODE (constructor_type) == UNION_TYPE) { - tree temp = size_binop (PLUS_EXPR, - DECL_FIELD_BITPOS (constructor_fields), - DECL_SIZE (constructor_fields)); + tree temp = size_binop (PLUS_EXPR, DECL_FIELD_BITPOS (field), + DECL_SIZE (field)); TREE_INT_CST_LOW (constructor_bit_index) = TREE_INT_CST_LOW (temp); TREE_INT_CST_HIGH (constructor_bit_index) @@ -5777,20 +5776,30 @@ output_pending_init_elements (all) if (TREE_CODE (constructor_type) == RECORD_TYPE || TREE_CODE (constructor_type) == UNION_TYPE) { - /* Find the last field written out. */ + /* Find the last field written out, if any. */ for (tail = TYPE_FIELDS (constructor_type); tail; tail = TREE_CHAIN (tail)) if (TREE_CHAIN (tail) == constructor_unfilled_fields) break; - /* Find the offset of the end of that field. */ - filled = size_binop (CEIL_DIV_EXPR, - size_binop (PLUS_EXPR, - DECL_FIELD_BITPOS (tail), - DECL_SIZE (tail)), - size_int (BITS_PER_UNIT)); + + if (tail) + /* Find the offset of the end of that field. */ + filled = size_binop (CEIL_DIV_EXPR, + size_binop (PLUS_EXPR, + DECL_FIELD_BITPOS (tail), + DECL_SIZE (tail)), + size_int (BITS_PER_UNIT)); + else + filled = size_int (0); + nextpos_tree = size_binop (CEIL_DIV_EXPR, DECL_FIELD_BITPOS (next), size_int (BITS_PER_UNIT)); + + TREE_INT_CST_HIGH (constructor_bit_index) + = TREE_INT_CST_HIGH (DECL_FIELD_BITPOS (next)); + TREE_INT_CST_LOW (constructor_bit_index) + = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (next)); constructor_unfilled_fields = next; } else if (TREE_CODE (constructor_type) == ARRAY_TYPE) -- 2.30.2