diff mbox

C++ PATCH for c++/50793 (incomplete value-initialization with default argument)

Message ID 4E9F4D43.3050302@redhat.com
State New
Headers show

Commit Message

Jason Merrill Oct. 19, 2011, 10:20 p.m. UTC
When bot_manip regenerates TARGET_EXPR/AGGR_INIT_EXPR, it needs to 
preserve the AGGR_INIT_ZERO_FIRST flag.

Tested x86_64-pc-linux-gnu, applying to trunk and release branches.
diff mbox

Patch

commit f56f4ec3e3620b4ae4e07986a17338d607952c65
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Oct 19 17:21:34 2011 -0400

    	PR c++/50793
    	* tree.c (bot_manip): Propagate AGGR_INIT_ZERO_FIRST.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 75aa265..d023eb8 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -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);
diff --git a/gcc/testsuite/g++.dg/init/value9.C b/gcc/testsuite/g++.dg/init/value9.C
new file mode 100644
index 0000000..4899bd8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/value9.C
@@ -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();
+}