From patchwork Wed Oct 19 22:20:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 120696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2E69CB71C4 for ; Thu, 20 Oct 2011 09:21:12 +1100 (EST) Received: (qmail 27355 invoked by alias); 19 Oct 2011 22:21:09 -0000 Received: (qmail 27339 invoked by uid 22791); 19 Oct 2011 22:21:08 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Oct 2011 22:20:53 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9JMKrn4009675 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Oct 2011 18:20:53 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9JMKq2i007483 for ; Wed, 19 Oct 2011 18:20:53 -0400 Received: from [0.0.0.0] (ovpn-113-91.phx2.redhat.com [10.3.113.91]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p9JMKpVT031833 for ; Wed, 19 Oct 2011 18:20:52 -0400 Message-ID: <4E9F4D43.3050302@redhat.com> Date: Wed, 19 Oct 2011 18:20:51 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50793 (incomplete value-initialization with default argument) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. commit f56f4ec3e3620b4ae4e07986a17338d607952c65 Author: Jason Merrill 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(); +}