From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/50793 (incomplete value-initialization with default argument)
Date: Wed, 19 Oct 2011 22:32:00 -0000 [thread overview]
Message-ID: <4E9F4D43.3050302@redhat.com> (raw)
[-- 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();
+}
reply other threads:[~2011-10-19 22:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E9F4D43.3050302@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).