From 281ec92f7e7888aad2781d28cea88d98b01c432e Mon Sep 17 00:00:00 2001 From: Richard Stallman Date: Wed, 27 Oct 1993 21:42:09 +0000 Subject: [PATCH] (output_pending_init_elements): Don't crash if constructor_unfilled_fields is 0. (build_c_cast): When making union constructor, copy TREE_CONSTANT from the given value. (initializer_constant_valid_p): Special handling for "constant" union constructor. From-SVN: r5921 --- gcc/c-typeck.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index da34eee6195..11ed850db47 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3469,7 +3469,7 @@ build_c_cast (type, expr) if (field) { char *name; - tree nvalue; + tree t; if (pedantic) pedwarn ("ANSI C forbids casts to union type"); @@ -3482,9 +3482,11 @@ build_c_cast (type, expr) } else name = ""; - return digest_init (type, build (CONSTRUCTOR, type, NULL_TREE, - build_tree_list (field, value)), - 0, 0); + t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE, + build_tree_list (field, value)), + 0, 0); + TREE_CONSTANT (t) = TREE_CONSTANT (value); + return t; } error ("cast to union type from type not present in union"); return error_mark_node; @@ -4033,6 +4035,10 @@ initializer_constant_valid_p (value, endtype) switch (TREE_CODE (value)) { case CONSTRUCTOR: + if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE + && TREE_CONSTANT (value)) + return initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value))); + return TREE_STATIC (value) ? null_pointer_node : 0; case INTEGER_CST: @@ -5688,8 +5694,9 @@ output_pending_init_elements (all) 0); goto retry; } - else if (tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)), - DECL_FIELD_BITPOS (constructor_unfilled_fields))) + else if (constructor_unfilled_fields == 0 + || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)), + DECL_FIELD_BITPOS (constructor_unfilled_fields))) ; else if (next == 0 || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)), -- 2.30.2