From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 107072 invoked by alias); 29 Mar 2017 16:38:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 107055 invoked by uid 89); 29 Mar 2017 16:38:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=crept, 4967 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; Wed, 29 Mar 2017 16:38:11 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 AA461B0409 for ; Wed, 29 Mar 2017 16:38:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AA461B0409 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AA461B0409 Received: from redhat.com (ovpn-204-110.brq.redhat.com [10.40.204.110]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2TGc8Di019652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 29 Mar 2017 12:38:10 -0400 Date: Wed, 29 Mar 2017 17:08:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/80095, ICE with this pointer in NSDMI Message-ID: <20170329163808.GS3172@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-SW-Source: 2017-03/txt/msg01479.txt.bz2 Here we have a reference initialization with NSDMI and *this. We are crashing because a PLACEHOLDER_EXPR crept into the gimplifier. This happens since r218653 where set_up_extended_ref_temp was changed to use split_nonconstant_init. As a consequence, cp_gimplify_init_expr might now be receiving D.2051.p = (void *) & instead of D.2051 = {.p = (void *) &} where the RHS was a CONSTRUCTOR. It no longer is, so replace_placeholders is not called anymore. It occurred to me that we should use the same check as in store_init_value (i.e. check that the object to be used in the substitution is a class), but given what split_nonconstant_init might produce, handle COMPONENT_REFs specially. Bootstrapped/regtested on x86_64-linux, ok for trunk and 6? 2017-03-29 Marek Polacek PR c++/80095 - ICE with this pointer in NSDMI. * cp-gimplify.c (cp_gimplify_init_expr): Call replace_placeholders when TO is a class. * g++.dg/cpp1y/nsdmi-aggr8.C: New test. diff --git gcc/cp/cp-gimplify.c gcc/cp/cp-gimplify.c index 354ae1a..e530daf 100644 --- gcc/cp/cp-gimplify.c +++ gcc/cp/cp-gimplify.c @@ -496,7 +496,16 @@ cp_gimplify_init_expr (tree *expr_p) TREE_TYPE (from) = void_type_node; } - if (cxx_dialect >= cxx14 && TREE_CODE (sub) == CONSTRUCTOR) + /* split_nonconstant_init might've produced something like + D.2051.p = (void *) & + in which case we want to substitute the placeholder with + D.2051. */ + tree op0 = to; + while (TREE_CODE (op0) == COMPONENT_REF) + op0 = TREE_OPERAND (op0, 0); + tree type = TREE_TYPE (op0); + + if (cxx_dialect >= cxx14 && CLASS_TYPE_P (strip_array_types (type))) /* Handle aggregate NSDMI. */ replace_placeholders (sub, to); diff --git gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C index e69de29..8c99ffb 100644 --- gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C +++ gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C @@ -0,0 +1,16 @@ +// PR c++/80095 +// { dg-do compile { target c++14 } } + +struct A +{ + void* p = this; +}; + +void +foo () +{ + const A& a = A{}; + A&& a2 = A{}; + const A& a3{}; + A&& a4{}; +} Marek