From patchwork Tue Feb 21 16:44:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 730688 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vSRDs1l7Lz9s2Q for ; Wed, 22 Feb 2017 03:45:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="c+URye5p"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=ghmKq92QUlQbOERxALO/oNVLEMtqG 8fSTMbBLZ17bOCnHqZors1JiGa56MT59mdVp2WM+6uoGBzRPrrje0SSJeLUMigUv 1KlFHtwDpFuNFSBkvxzmF515UZjZMpv1Fc6xe1ixukp3IWhlkzUpNQc4DMMcRRVV ZpFgX/7Evb54fU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=uBDwtWBT5UI1X1uQfm+7mlQH3mM=; b=c+U Rye5pkiAg+NXcjKYfDvqaXZbd0AbgMWLLOoaxZ1FySHi7BmCJ6MxkHxTVxNPVS43 xME808brgmD6Mtmx4fXcCzj/+edPUbGQKRwb95cLNgZxDp3OCt3M+yqroU4o2t5j oV0iqjm0AyztMzmlbd1snohuQLARRs+8VWt90PRs= Received: (qmail 75044 invoked by alias); 21 Feb 2017 16:44:52 -0000 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 Received: (qmail 75032 invoked by uid 89); 21 Feb 2017 16:44:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Feb 2017 16:44:50 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1CE780F95 for ; Tue, 21 Feb 2017 16:44:50 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-76.ams2.redhat.com [10.36.117.76]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LGinLJ010581 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 21 Feb 2017 11:44:50 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v1LGik9F017184; Tue, 21 Feb 2017 17:44:47 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v1LGikqO017183; Tue, 21 Feb 2017 17:44:46 +0100 Date: Tue, 21 Feb 2017 17:44:46 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE with constexpr store to pointer to method (PR c++/79639) Message-ID: <20170221164446.GU1849@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! Apparently we can end up trying to store into a pointer-to-member that has a PTRMEM_CST as its current value. Later code in cxx_eval_store_expression is upset that it isn't a CONSTRUCTOR when the type is actually aggregate. The following patch fixes that, bootstrapped/regtested on x86_64-linux and i686-linux, though I admit I'm not really sure if this is the best fix. 2017-02-21 Jakub Jelinek PR c++/79639 * constexpr.c (cxx_eval_store_expression): If *valp is a PTRMEM_CST, call cplus_expand_constant on it first. * g++.dg/cpp1y/constexpr-79639.C: New test. Jakub --- gcc/cp/constexpr.c.jj 2017-02-21 13:49:06.000000000 +0100 +++ gcc/cp/constexpr.c 2017-02-21 14:57:30.290440638 +0100 @@ -3518,11 +3518,12 @@ cxx_eval_store_expression (const constex wants to modify it. */ if (*valp == NULL_TREE) { - *valp = new_ctx.ctor = build_constructor (type, NULL); - CONSTRUCTOR_NO_IMPLICIT_ZERO (new_ctx.ctor) = no_zero_init; + *valp = build_constructor (type, NULL); + CONSTRUCTOR_NO_IMPLICIT_ZERO (*valp) = no_zero_init; } - else - new_ctx.ctor = *valp; + else if (TREE_CODE (*valp) == PTRMEM_CST) + *valp = cplus_expand_constant (*valp); + new_ctx.ctor = *valp; new_ctx.object = target; } --- gcc/testsuite/g++.dg/cpp1y/constexpr-79639.C.jj 2017-02-21 15:06:42.625475572 +0100 +++ gcc/testsuite/g++.dg/cpp1y/constexpr-79639.C 2017-02-21 15:06:07.000000000 +0100 @@ -0,0 +1,27 @@ +// PR c++/79639 +// { dg-do compile { target c++14 } } + +struct A +{ + void foo () {} + void bar () {} +}; +typedef void (A::*T) (); + +constexpr T +foo (T f) +{ + f = 0; + return f; +} + +constexpr T +bar (T f) +{ + f = &A::bar; + return f; +} + +constexpr T a = foo (&A::foo); +constexpr T b = foo (&A::foo); +static_assert (a == nullptr, "");