]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/50793 (G++ doesn't value-initialize all members of non-trivial type in...
authorJason Merrill <jason@redhat.com>
Wed, 19 Oct 2011 22:21:15 +0000 (18:21 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 19 Oct 2011 22:21:15 +0000 (18:21 -0400)
PR c++/50793
* tree.c (bot_manip): Propagate AGGR_INIT_ZERO_FIRST.

From-SVN: r180223

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/value9.C [new file with mode: 0644]

index 3797b3a7a2708445b90ba43f0fe86aa23a763297..7276a3f2d63ff81e3cb1e023b665ee22d98c06c8 100644 (file)
@@ -1,3 +1,8 @@
+2011-10-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50793
+       * tree.c (bot_manip): Propagate AGGR_INIT_ZERO_FIRST.
+
 2011-10-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/50618
index dcf9872d346a660572b1fb8e38bae15b81164e34..01f4b6a031fc7e28389cef42b82a6481283a4579 100644 (file)
@@ -1536,7 +1536,11 @@ bot_manip (tree* tp, int* walk_subtrees, void* data)
       tree u;
 
       if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
-       u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1));
+       {
+         u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1));
+         if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t, 1)))
+           AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true;
+       }
       else
        u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t));
 
index 474b7283fae5cb674a41b72e3997b177eb104e96..c1a4ebeca8661f62526ad85525bec80fbfa2d48e 100644 (file)
@@ -1,3 +1,8 @@
+2011-10-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50793
+       * g++.dg/init/value9.C: New.
+
 2011-10-15  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/50659
diff --git a/gcc/testsuite/g++.dg/init/value9.C b/gcc/testsuite/g++.dg/init/value9.C
new file mode 100644 (file)
index 0000000..4899bd8
--- /dev/null
@@ -0,0 +1,32 @@
+// PR c++/50793
+// { dg-do run }
+
+struct NonTrivial
+{
+  NonTrivial() { }
+};
+
+struct S
+{
+  NonTrivial nt;
+  int i;
+};
+
+int f(S s)
+{
+  s.i = 0xdeadbeef;
+  return s.i;
+}
+
+int g(S s = S())
+{
+  return s.i;
+}
+
+int main()
+{
+  f(S());  // make stack dirty
+
+  if ( g() )
+    __builtin_abort();
+}