OSDN Git Service

gcc toplevel:
authoramylaar <amylaar@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Oct 1999 02:18:10 +0000 (02:18 +0000)
committeramylaar <amylaar@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Oct 1999 02:18:10 +0000 (02:18 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@29956 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/union2.C [new file with mode: 0644]

index 243cff9..1bdfbce 100644 (file)
@@ -1,3 +1,7 @@
+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.
index 9c421a8..3593ce4 100644 (file)
@@ -1,3 +1,7 @@
+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.
index 4b37e48..cb089d4 100644 (file)
@@ -921,7 +921,9 @@ process_init_constructor (type, init, elts)
          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);
 
index 79e651f..e246020 100644 (file)
@@ -4073,7 +4073,14 @@ store_constructor (exp, target, align, cleared)
       /* 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
index 4756349..e6db32a 100644 (file)
@@ -1,3 +1,7 @@
+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.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/union2.C b/gcc/testsuite/g++.old-deja/g++.other/union2.C
new file mode 100644 (file)
index 0000000..32dd26c
--- /dev/null
@@ -0,0 +1,36 @@
+// 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;
+}