aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1993-10-27 21:42:09 +0000
committerRichard Stallman <rms@gnu.org>1993-10-27 21:42:09 +0000
commit281ec92f7e7888aad2781d28cea88d98b01c432e (patch)
tree0ce4a17ec5169721cb9ea1ab6898d915124e212d
parentb73d04f2fd8deea3df7920e69710a7accfdca162 (diff)
downloadgcc-281ec92f7e7888aad2781d28cea88d98b01c432e.zip
gcc-281ec92f7e7888aad2781d28cea88d98b01c432e.tar.gz
gcc-281ec92f7e7888aad2781d28cea88d98b01c432e.tar.bz2
(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
-rw-r--r--gcc/c-typeck.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index da34eee..11ed850 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)),