From patchwork Tue Oct 25 19:00:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 121781 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 15AEAB6F6F for ; Wed, 26 Oct 2011 06:01:02 +1100 (EST) Received: (qmail 2307 invoked by alias); 25 Oct 2011 19:00:56 -0000 Received: (qmail 2296 invoked by uid 22791); 25 Oct 2011 19:00:55 -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; Tue, 25 Oct 2011 19:00:36 +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 p9PJ0Zx5006160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 Oct 2011 15:00:35 -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 p9PJ0ZEd005476 for ; Tue, 25 Oct 2011 15:00:35 -0400 Received: from [0.0.0.0] (ovpn-113-169.phx2.redhat.com [10.3.113.169]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p9PJ0XAG024549 for ; Tue, 25 Oct 2011 15:00:34 -0400 Message-ID: <4EA70751.7090601@redhat.com> Date: Tue, 25 Oct 2011 15:00:33 -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++/49996 (stray gimple_with_cleanup_expr with new and init-list) 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 In a new-expression, we try to pre-evaluate all of the arguments to a constructor before allocating the memory in order to improve EH region nesting. In the case of a list-initialized object, we want to pre-evaluate the arguments to any constructors for each of the subobjects. If the subobject is scalar, we also want to pre-evaluate its value; this patch adds that. Tested x86_64-pc-linux-gnu, applying to trunk. commit f1a7cdfc760884b87fc888e70c34f3268d77aeac Author: Jason Merrill Date: Tue Oct 25 10:37:47 2011 -0400 PR c++/49996 * tree.c (stabilize_init): Stabilize scalar elements of a CONSTRUCTOR, too. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index d023eb8..707f2c8 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3345,11 +3345,20 @@ stabilize_init (tree init, tree *initp) /* Aggregate initialization: stabilize each of the field initializers. */ unsigned i; - tree value; + constructor_elt *ce; bool good = true; - FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), i, value) - if (!stabilize_init (value, initp)) - good = false; + VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (t); + for (i = 0; VEC_iterate (constructor_elt, v, i, ce); ++i) + { + tree type = TREE_TYPE (ce->value); + tree subinit; + if (TREE_CODE (type) == REFERENCE_TYPE + || SCALAR_TYPE_P (type)) + ce->value = stabilize_expr (ce->value, &subinit); + else if (!stabilize_init (ce->value, &subinit)) + good = false; + *initp = add_stmt_to_compound (*initp, subinit); + } return good; } diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist59.C b/gcc/testsuite/g++.dg/cpp0x/initlist59.C new file mode 100644 index 0000000..2cc015d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist59.C @@ -0,0 +1,18 @@ +// PR c++/49996 +// { dg-options -std=c++0x } + +struct A +{ + ~A() + { } +}; + +struct B +{ + const A& ref; +}; + +int main() +{ + B* p = new B{A()}; +}