From patchwork Thu Feb 7 21:30:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 218994 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 812992C008D for ; Fri, 8 Feb 2013 08:31:56 +1100 (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=1360877517; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=F+t45Ylp3qI9JRKuLmYY diJY2Kw=; b=sH80eNL5pqVWYC4PPz6FwWnsjwoytxgH2B/r4NlaHwUpgO55BfQN xzJIIaHCHtF4XCEAf8bhjIEVjRX+/V4CjSB/9DEpyhWzIDYOMQVGyQIbxABdfeYg KkJEN0okQ5uH5BAnw3/+u1Yx1p5RpLkvzoWrjEkEEgT9wnNftlSromI= 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:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=X2Cc+Fi1KmAiOb5kuPdyKNZrQmCme9Iwd+Pt8OEDfBCptQ7plyh8IACUpvjeDS xv2vTQrp3/u+TptpcnrXb01tQAKnaZf6vhYKEATFUOclMU0gzAjo/mqWXi9CWBED C2dhsNC116uJvoyga39WD3l+MqnrgE7DgCGhDM/U3Jyiw=; Received: (qmail 2912 invoked by alias); 7 Feb 2013 21:31:29 -0000 Received: (qmail 2896 invoked by uid 22791); 7 Feb 2013 21:31:27 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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; Thu, 07 Feb 2013 21:30:49 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r17LUea7021338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Feb 2013 16:30:42 -0500 Received: from zalov.redhat.com (vpn1-5-55.ams2.redhat.com [10.36.5.55]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r17LUT4O022847 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 7 Feb 2013 16:30:31 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r17LUToJ001177; Thu, 7 Feb 2013 22:30:29 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r17LUSSR001176; Thu, 7 Feb 2013 22:30:28 +0100 Date: Thu, 7 Feb 2013 22:30:27 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [committed] Fix up C++ ICEs in build_constructor (PR c++/56241) Message-ID: <20130207213027.GJ4385@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! build_constructor assumes the elts it is called with have all non-NULL value, otherwise one shouldn't add those elts at all. The following patch makes sure that we don't push elts with NULL value into the ctor element vectors. Bootstrapped/regtested on x86_64-linux and i686-linux, approved by Jason in the PR, committed to trunk. 2013-02-07 Jakub Jelinek PR c++/56241 * init.c (build_vec_init): Don't append NULL values into new_vec. (build_zero_init_1): Don't push anything into v if recursive call returned NULL_TREE. (build_value_init_noctor): Don't push anything into v if build_value_init call returned NULL_TREE. * g++.dg/parse/crash61.C: New test. Jakub --- gcc/cp/init.c.jj 2013-02-07 17:40:59.432029399 +0100 +++ gcc/cp/init.c 2013-02-07 19:05:02.044062934 +0100 @@ -253,8 +253,6 @@ build_zero_init_1 (tree type, tree nelts { constructor_elt ce; - vec_alloc (v, 1); - /* If this is a one element array, we just use a regular init. */ if (tree_int_cst_equal (size_zero_node, max_index)) ce.index = size_zero_node; @@ -265,7 +263,11 @@ build_zero_init_1 (tree type, tree nelts ce.value = build_zero_init_1 (TREE_TYPE (type), /*nelts=*/NULL_TREE, static_storage_p, NULL_TREE); - v->quick_push (ce); + if (ce.value) + { + vec_alloc (v, 1); + v->quick_push (ce); + } } /* Build a constructor to contain the initializations. */ @@ -447,8 +449,6 @@ build_value_init_noctor (tree type, tsub { constructor_elt ce; - vec_alloc (v, 1); - /* If this is a one element array, we just use a regular init. */ if (tree_int_cst_equal (size_zero_node, max_index)) ce.index = size_zero_node; @@ -456,16 +456,20 @@ build_value_init_noctor (tree type, tsub ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node, max_index); ce.value = build_value_init (TREE_TYPE (type), complain); - v->quick_push (ce); + if (ce.value) + { + if (ce.value == error_mark_node) + return error_mark_node; - if (ce.value == error_mark_node) - return error_mark_node; + vec_alloc (v, 1); + v->quick_push (ce); - /* We shouldn't have gotten here for anything that would need - non-trivial initialization, and gimplify_init_ctor_preeval - would need to be fixed to allow it. */ - gcc_assert (TREE_CODE (ce.value) != TARGET_EXPR - && TREE_CODE (ce.value) != AGGR_INIT_EXPR); + /* We shouldn't have gotten here for anything that would need + non-trivial initialization, and gimplify_init_ctor_preeval + would need to be fixed to allow it. */ + gcc_assert (TREE_CODE (ce.value) != TARGET_EXPR + && TREE_CODE (ce.value) != AGGR_INIT_EXPR); + } } /* Build a constructor to contain the initializations. */ @@ -3469,9 +3473,12 @@ build_vec_init (tree base, tree maxindex else { if (do_static_init) - CONSTRUCTOR_APPEND_ELT (new_vec, field, - build_zero_init (TREE_TYPE (e), - NULL_TREE, true)); + { + tree value = build_zero_init (TREE_TYPE (e), NULL_TREE, + true); + if (value) + CONSTRUCTOR_APPEND_ELT (new_vec, field, value); + } saw_non_const = true; } } --- gcc/testsuite/g++.dg/parse/crash61.C.jj 2013-02-07 19:03:49.713481742 +0100 +++ gcc/testsuite/g++.dg/parse/crash61.C 2013-02-07 19:03:49.713481742 +0100 @@ -0,0 +1,6 @@ +// PR c++/56241 +// { dg-do compile } + +struct pair { constexpr pair (const) : }; // { dg-error "" } +template <0> make_pair () {} // { dg-error "" } +pair prefix[] = { 0, make_pair } // { dg-error "" }