Commit 486e4326 by Richard Henderson Committed by Richard Henderson

re PR middle-end/19687 (ICE with union initializer)

        PR middle-end/19687
        * expr.c (categorize_ctor_elements_1): Check for CONSTRUCTOR of a
        union being empty.

From-SVN: r94421
parent eb2ab511
2005-01-29 Richard Henderson <rth@redhat.com> 2005-01-29 Richard Henderson <rth@redhat.com>
PR middle-end/19687
* expr.c (categorize_ctor_elements_1): Check for CONSTRUCTOR of a
union being empty.
2005-01-29 Richard Henderson <rth@redhat.com>
* combine.c (make_field_assignment): Fix argument order * combine.c (make_field_assignment): Fix argument order
to gen_int_mode. to gen_int_mode.
......
...@@ -4364,10 +4364,13 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts, ...@@ -4364,10 +4364,13 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts,
|| TREE_CODE (TREE_TYPE (ctor)) == QUAL_UNION_TYPE)) || TREE_CODE (TREE_TYPE (ctor)) == QUAL_UNION_TYPE))
{ {
tree init_sub_type; tree init_sub_type;
bool clear_this = true;
list = CONSTRUCTOR_ELTS (ctor);
if (list)
{
/* We don't expect more than one element of the union to be /* We don't expect more than one element of the union to be
initialized. Not sure what we should do otherwise... */ initialized. Not sure what we should do otherwise... */
list = CONSTRUCTOR_ELTS (ctor);
gcc_assert (TREE_CHAIN (list) == NULL); gcc_assert (TREE_CHAIN (list) == NULL);
init_sub_type = TREE_TYPE (TREE_VALUE (list)); init_sub_type = TREE_TYPE (TREE_VALUE (list));
...@@ -4382,11 +4385,12 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts, ...@@ -4382,11 +4385,12 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts,
/* And now we have to find out if the element itself is fully /* And now we have to find out if the element itself is fully
constructed. E.g. for union { struct { int a, b; } s; } u constructed. E.g. for union { struct { int a, b; } s; } u
= { .s = { .a = 1 } }. */ = { .s = { .a = 1 } }. */
if (elt_count != count_type_elements (init_sub_type)) if (elt_count == count_type_elements (init_sub_type))
*p_must_clear = true; clear_this = false;
} }
else }
*p_must_clear = true;
*p_must_clear = clear_this;
} }
*p_nz_elts += nz_elts; *p_nz_elts += nz_elts;
......
extern void abort (void);
union U
{
int i, j[4];
};
int main ()
{
union U t = {};
int i;
for (i = 0; i < 4; ++i)
if (t.j[i] != 0)
abort ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment