* 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
+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>
* 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>
* decl.c (lang_mark_tree): Mark NAMESPACE_LEVEL.
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);
/* Inform later passes that the whole union value is dead. */
if (TREE_CODE (type) == 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,
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>
* g++.old-deja/g++.other/vaarg2.C: New test.
--- /dev/null
+// 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;
+}