From patchwork Wed May 30 21:58:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 162086 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 CF84EB7027 for ; Thu, 31 May 2012 07:59:07 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339019949; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=DywxXzli0xmjjFbqyvtHL56eBO8=; b=kVOQE6d1hvpQrBX QSj2imiJ5sZ7u76EPRfkeyxPOyz5BoHQPMLhWGpIzsrAh4uw9M+wEw19X/QhT+1K 0E5vR266ra2gBls8Q70UZqVNfRAk11WVyv/66gv74OLUliUWZ1Syn9WnfSXcVfia i94zbr+ywA29o1S9EBNfnzufSOGU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=t/8h7zTYKAQMLhpPNOMZgttPi/HtQyjU364S0yohPv7FEhkRXbyQfISaoWdgQh uMqbUgj4bqjh1ofPTKWcXnF8gMXLkd0WC7j1yMDepx4/u2/enCkwYe0Xqhexrsqk N202yBrtf/oXNrB3eH3B4vAs3ZbYZLIYaA+q8CRllf4TA=; Received: (qmail 23860 invoked by alias); 30 May 2012 21:59:04 -0000 Received: (qmail 23851 invoked by uid 22791); 30 May 2012 21:59:02 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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, 30 May 2012 21:58:44 +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 q4ULwiAZ032720 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 30 May 2012 17:58:44 -0400 Received: from [10.3.113.58] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4ULwhDT017758 for ; Wed, 30 May 2012 17:58:44 -0400 Message-ID: <4FC69813.6050809@redhat.com> Date: Wed, 30 May 2012 17:58:43 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: Re: C++ PATCH for c++/53356 (C++11 ICE with new) References: <4FC63267.9070700@redhat.com> In-Reply-To: <4FC63267.9070700@redhat.com> 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 On 05/30/2012 10:44 AM, Jason Merrill wrote: > The code in build_new_1 already knows how to handle an initializer that > it was unable to stabilize, but the logic was backwards in a critical > place. I'm surprised this typo hasn't been hit before since it was > introduced in 2006... ...and then this patch fixes stabilize_init to actually stabilize the initializer in this case. And fixes another case I noticed that has been ICEing since 4.0. Tested x86_64-pc-linux-gnu, applying to trunk. I'm not going to apply it to 4.7 because nobody has noticed the other issue. commit 3f176267c61a889926e3f518ccd79cf55c5e7de1 Author: Jason Merrill Date: Wed May 30 17:31:57 2012 -0400 PR c++/53356 * tree.c (stabilize_init): Handle stabilizing a TARGET_EXPR representing a bitwise copy of a glvalue. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 4e7056f..2b541cd 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3389,7 +3389,7 @@ stabilize_aggr_init (tree call, tree *initp) takes care not to introduce additional temporaries. Returns TRUE iff the expression was successfully pre-evaluated, - i.e., if INIT is now side-effect free, except for, possible, a + i.e., if INIT is now side-effect free, except for, possibly, a single call to a constructor. */ bool @@ -3402,21 +3402,37 @@ stabilize_init (tree init, tree *initp) if (t == error_mark_node || processing_template_decl) return true; - if (TREE_CODE (t) == INIT_EXPR - && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR - && TREE_CODE (TREE_OPERAND (t, 1)) != CONSTRUCTOR - && TREE_CODE (TREE_OPERAND (t, 1)) != AGGR_INIT_EXPR) - { - TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp); - return true; - } - if (TREE_CODE (t) == INIT_EXPR) t = TREE_OPERAND (t, 1); if (TREE_CODE (t) == TARGET_EXPR) t = TARGET_EXPR_INITIAL (t); - if (TREE_CODE (t) == COMPOUND_EXPR) - t = expr_last (t); + + /* If the RHS can be stabilized without breaking copy elision, stabilize + it. We specifically don't stabilize class prvalues here because that + would mean an extra copy, but they might be stabilized below. */ + if (TREE_CODE (init) == INIT_EXPR + && TREE_CODE (t) != CONSTRUCTOR + && TREE_CODE (t) != AGGR_INIT_EXPR + && (SCALAR_TYPE_P (TREE_TYPE (t)) + || lvalue_or_rvalue_with_address_p (t))) + { + TREE_OPERAND (init, 1) = stabilize_expr (t, initp); + return true; + } + + if (TREE_CODE (t) == COMPOUND_EXPR + && TREE_CODE (init) == INIT_EXPR) + { + tree last = expr_last (t); + /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */ + if (!TREE_SIDE_EFFECTS (last)) + { + *initp = t; + TREE_OPERAND (init, 1) = last; + return true; + } + } + if (TREE_CODE (t) == CONSTRUCTOR) { /* Aggregate initialization: stabilize each of the field @@ -3439,11 +3455,6 @@ stabilize_init (tree init, tree *initp) return good; } - /* If the initializer is a COND_EXPR, we can't preevaluate - anything. */ - if (TREE_CODE (t) == COND_EXPR) - return false; - if (TREE_CODE (t) == CALL_EXPR) { stabilize_call (t, initp); diff --git a/gcc/testsuite/g++.dg/init/new34.C b/gcc/testsuite/g++.dg/init/new34.C new file mode 100644 index 0000000..9e67eb34 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new34.C @@ -0,0 +1,11 @@ +// PR c++/53356 + +struct A { A(); ~A(); }; + +struct B { + operator const A () const; +}; + +A* cause_ICE() { + return new A((A(),A())); +} diff --git a/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C b/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C new file mode 100644 index 0000000..2fe723c --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C @@ -0,0 +1,14 @@ +// PR c++/53356 +// { dg-options "-fdump-tree-gimple" } +// { dg-final { scan-tree-dump-not "= 0" "gimple" } } +// { dg-final { cleanup-tree-dump "gimple" } } + +class A {}; + +struct B { + operator const A &() const; +}; + +A* cause_ICE() { + return new A(B()); +}