]> 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:29:15 +0000 (18:29 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 19 Oct 2011 22:29:15 +0000 (18:29 -0400)
PR c++/50793
* tree.c (bot_manip): Propagate AGGR_INIT_ZERO_FIRST.

From-SVN: r180227

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

index 3b5c14c007786824f44079b3ff4863c819964805..8e9bb4a841df9b7a6922e20ac185f858d71a8b62 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-19  Roland Stigge  <stigge@antcom.de>
 
        PR translation/49704
index 75aa26503006e225a6af3eb9994d9cd1424c96c3..d023eb86cb8d648f1542589642323c40363aa51e 100644 (file)
@@ -1879,8 +1879,12 @@ 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),
-                            tf_warning_or_error);
+       {
+         u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1),
+                              tf_warning_or_error);
+         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),
                                         tf_warning_or_error);
index 12392074311c99868d59557792371ca9b5509833..173f195f2766821092ac7f4f4a3fbf6b5e05a4b5 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-19  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.dg/torture/vshuf-32.inc: Add interleave permutations.
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();
+}