Commit a59f8640 by J"orn Rennecke Committed by Joern Rennecke

gcc toplevel:

	* expr.c (store_constructor): Clear union if constructor is empty.
cp:
	* typeck2.c (process_init_constructor): Handle empty constructors.
testsuite:
	* g++.old-deja/g++.other/union2.C: New test.

From-SVN: r29956
parent 5cf531a8
Wed Oct 13 22:01:35 1999 J"orn Rennecke <amylaar@cygnus.co.uk>
* expr.c (store_constructor): Clear union if constructor is empty.
Wed Oct 13 15:19:04 1999 Jim Wilson <wilson@cygnus.com> Wed Oct 13 15:19:04 1999 Jim Wilson <wilson@cygnus.com>
* config/rs6000/sysv4.h (CC1_SPEC): Fix errors from Jan 19 change. * config/rs6000/sysv4.h (CC1_SPEC): Fix errors from Jan 19 change.
......
Wed Oct 13 22:01:35 1999 J"orn Rennecke <amylaar@cygnus.co.uk>
* typeck2.c (process_init_constructor): Handle empty constructors.
1999-10-13 Jason Merrill <jason@yorick.cygnus.com> 1999-10-13 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (lang_mark_tree): Mark NAMESPACE_LEVEL. * decl.c (lang_mark_tree): Mark NAMESPACE_LEVEL.
......
...@@ -921,7 +921,9 @@ process_init_constructor (type, init, elts) ...@@ -921,7 +921,9 @@ process_init_constructor (type, init, elts)
members = expr_tree_cons (field, next1, members); members = expr_tree_cons (field, next1, members);
} }
} }
else if (TREE_CODE (type) == UNION_TYPE) else if (TREE_CODE (type) == UNION_TYPE
/* If the initializer was empty, use default zero initialization. */
&& tail)
{ {
register tree field = TYPE_FIELDS (type); register tree field = TYPE_FIELDS (type);
......
...@@ -4073,7 +4073,14 @@ store_constructor (exp, target, align, cleared) ...@@ -4073,7 +4073,14 @@ store_constructor (exp, target, align, cleared)
/* Inform later passes that the whole union value is dead. */ /* Inform later passes that the whole union value is dead. */
if (TREE_CODE (type) == UNION_TYPE if (TREE_CODE (type) == UNION_TYPE
|| TREE_CODE (type) == QUAL_UNION_TYPE) || TREE_CODE (type) == QUAL_UNION_TYPE)
emit_insn (gen_rtx_CLOBBER (VOIDmode, target)); {
emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
/* If the constructor is empty, clear the union. */
if (! CONSTRUCTOR_ELTS (exp) && ! cleared)
clear_storage (target, expr_size (exp),
TYPE_ALIGN (type) / BITS_PER_UNIT);
}
/* If we are building a static constructor into a register, /* If we are building a static constructor into a register,
set the initial value as zero so we can fold the value into set the initial value as zero so we can fold the value into
......
Wed Oct 13 22:01:35 1999 J"orn Rennecke <amylaar@cygnus.co.uk>
* g++.old-deja/g++.other/union2.C: New test.
1999-10-13 Nathan Sidwell <nathan@acm.org> 1999-10-13 Nathan Sidwell <nathan@acm.org>
* g++.old-deja/g++.other/vaarg2.C: New test. * g++.old-deja/g++.other/vaarg2.C: New test.
......
// Bug: g++ crashed on empty intializers for unions.
// Bug: gcc and g++ didn't zero unions with empty initializers.
// Submitted by J"orn Rennecke <amylaar@cygnus.co.uk>
typedef union u
{
union u *up;
void *vp;
} u;
static u v = {};
void bar (u);
void baz (u);
void foo()
{
u w = {};
u x = { &v };
baz (x);
bar (w);
}
void baz (u w) { }
void bar (u w)
{
if (w.up)
exit (1);
}
int main ()
{
foo ();
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