public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/50793 (incomplete value-initialization with default argument)
@ 2011-10-19 22:32 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-10-19 22:32 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 177 bytes --]

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.

[-- Attachment #2: 50793.patch --]
[-- Type: text/x-patch, Size: 1408 bytes --]

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();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-10-19 22:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-19 22:32 C++ PATCH for c++/50793 (incomplete value-initialization with default argument) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).