From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 24DBE3858C36 for ; Tue, 12 Mar 2024 22:26:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24DBE3858C36 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 24DBE3858C36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710282380; cv=none; b=rn1CLxdoghkrOnN6ag9lSEj3nhXRS8cfL6hySJW3Cmj6braCZNzpyyV0CSbVoPUYP+IO1y5RlpO+KHGW5ERNs/nxMpI3v1i3MJmCbwAJwbsHN5CtJ+zxkorUg2WRcim+TqcV3rOJzRnk5ZV3dhXcFrIupgwehmjVRqw+3i2g+9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710282380; c=relaxed/simple; bh=6GpoI1gsZfKTDZLU6HLdU7fBtxv0t8ogSkwjQL1dF/4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=mQRGxRG/r65/bbD+mM1L0NXs4qN7CaADw6V3L5bINpUkpZd2le+5bABtgiDAqdiPb+PeWiHWM829dj2T9sE8GkBEgNNdEc2ZKIsrNRv4fM/JbmKzIIivLV+wyXLw/BUmB13iGfgHZlcWhvRIIMZcMo6fBdmq+Kd+mX7zRys01WU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E+7N1ADD7rxq3xOUakqOi4k4Yxx5VRZxGMBvWG9EUbM=; b=X4rokKzGOzI6eU+Yy7ToaF+xjJDzGVZuQyvTvs8ciJoagSCMX6u8A7ptHkVa786olBxhyg XTtQRIiaiqbw00JuO0U0OVAfYEw8reeDtO1A4WrEXDiHCb1Dwjmg1cYZ4Aj5ED0qd1C74N 9uycD9QYqsiHRPHFuf4tpBm6lk25t4o= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-496-tzuSOHFlOyGRQSFUe4SKLw-1; Tue, 12 Mar 2024 18:26:16 -0400 X-MC-Unique: tzuSOHFlOyGRQSFUe4SKLw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-690d8b80e61so25518806d6.2 for ; Tue, 12 Mar 2024 15:26:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282376; x=1710887176; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E+7N1ADD7rxq3xOUakqOi4k4Yxx5VRZxGMBvWG9EUbM=; b=jPODQudJ4I4NNDaB3sPQK14ZuatRjL3O3L3C0oP9p2PEXgaiqEjoQx6eujmJ5v9ejP x/cAc2egdXyi0saFfBaHBOuIc84rM4+7kt1TlBVClijrtaKa3fMZvXHkA78q9PG8TgKm 2KCsiJPxVYWqqX8+rUEO5mZcpvquf3W9/v4KyRy+9zcokY2hUZGS1klFIptWrlYygd8M W53vVZsL3XBdQCX6uEdV2nEowzIKw6xz02BTw/hZppJVZ9p0oXZQkaZ7ZAYyuJr4abSY 5AZfflr1yeU8m8pU4uCCy+mob6yI3ZjXB1cPgnLQBno5hM5zXeNnCST7mP0pRINJE0yA s+sQ== X-Gm-Message-State: AOJu0Yy9AccH7NbtsJF7JbMp5CWRX0Jt9uiC1PuxcxqVUPbkpgnt0KFh ECInsuEXHfPpGXZO0b+Csms40xZDnijwa1351WuBld6BOsIS1rKvpFMZBqQ9WM4jj6Hewf25mKT L2KKBButY2UTB4ul6KBMrdF+ag5gaRZGAERJ+fhKA1GAMbH0kyJBpCX0= X-Received: by 2002:a05:6214:5c4:b0:690:bc2e:a67f with SMTP id t4-20020a05621405c400b00690bc2ea67fmr1554583qvz.37.1710282375994; Tue, 12 Mar 2024 15:26:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAIGbwbrX5A3fq3wy57AoTPs4aI9/oT1HVujsoEt50xEEPmyfUg64LjIQLIdo2LPAnxHQiRg== X-Received: by 2002:a05:6214:5c4:b0:690:bc2e:a67f with SMTP id t4-20020a05621405c400b00690bc2ea67fmr1554573qvz.37.1710282375638; Tue, 12 Mar 2024 15:26:15 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id u15-20020a0562140b0f00b00690796f7f3fsm4050733qvj.28.2024.03.12.15.26.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Mar 2024 15:26:14 -0700 (PDT) Message-ID: <2244ac04-8bb6-4030-85c6-7a10aa20c494@redhat.com> Date: Tue, 12 Mar 2024 18:26:14 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] c++: ICE with temporary of class type in array DMI [PR109966] To: Marek Polacek Cc: GCC Patches References: <20240311232758.458729-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 3/12/24 11:56, Marek Polacek wrote: > On Tue, Mar 12, 2024 at 09:57:14AM -0400, Jason Merrill wrote: >> On 3/11/24 19:27, Marek Polacek wrote: >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13? >>> >>> -- >8 -- >>> This ICE started with the fairly complicated r13-765. We crash in >>> gimplify_var_or_parm_decl because a stray VAR_DECL leaked there. >>> The problem is ultimately that potential_prvalue_result_of wasn't >>> correctly handling arrays and replace_placeholders_for_class_temp_r >>> replaced a PLACEHOLDER_EXPR in a TARGET_EXPR which is used in the >>> context of copy elision. If I have >>> >>> M m[2] = { M{""}, M{""} }; >>> >>> then we don't invoke the M(const M&) copy-ctor. I think the fix is >>> to detect such a case in potential_prvalue_result_of. >>> >>> PR c++/109966 >>> >>> gcc/cp/ChangeLog: >>> >>> * typeck2.cc (potential_prvalue_result_of): Add walk_subtrees >>> parameter. Handle initializing an array from a >>> brace-enclosed-initializer. >>> (replace_placeholders_for_class_temp_r): Pass walk_subtrees down to >>> potential_prvalue_result_of. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/cpp1y/nsdmi-aggr20.C: New test. >>> * g++.dg/cpp1y/nsdmi-aggr21.C: New test. >>> --- >>> gcc/cp/typeck2.cc | 27 ++++++++--- >>> gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr20.C | 17 +++++++ >>> gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr21.C | 59 +++++++++++++++++++++++ >>> 3 files changed, 96 insertions(+), 7 deletions(-) >>> create mode 100644 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr20.C >>> create mode 100644 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr21.C >>> >>> diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc >>> index 31198b2f9f5..8b99ce78e9a 100644 >>> --- a/gcc/cp/typeck2.cc >>> +++ b/gcc/cp/typeck2.cc >>> @@ -1406,46 +1406,59 @@ digest_init_flags (tree type, tree init, int flags, tsubst_flags_t complain) >>> A a = (A{}); // initializer >>> A a = (1, A{}); // initializer >>> A a = true ? A{} : A{}; // initializer >>> + A arr[1] = { A{} }; // initializer >>> auto x = A{}.x; // temporary materialization >>> auto x = foo(A{}); // temporary materialization >>> FULL_EXPR is the whole expression, SUBOB is its TARGET_EXPR subobject. */ >>> static bool >>> -potential_prvalue_result_of (tree subob, tree full_expr) >>> +potential_prvalue_result_of (tree subob, tree full_expr, int *walk_subtrees) >>> { >>> +#define RECUR(t) potential_prvalue_result_of (subob, t, walk_subtrees) >>> if (subob == full_expr) >>> return true; >>> else if (TREE_CODE (full_expr) == TARGET_EXPR) >>> { >>> tree init = TARGET_EXPR_INITIAL (full_expr); >>> if (TREE_CODE (init) == COND_EXPR) >>> - return (potential_prvalue_result_of (subob, TREE_OPERAND (init, 1)) >>> - || potential_prvalue_result_of (subob, TREE_OPERAND (init, 2))); >>> + return (RECUR (TREE_OPERAND (init, 1)) >>> + || RECUR (TREE_OPERAND (init, 2))); >>> else if (TREE_CODE (init) == COMPOUND_EXPR) >>> - return potential_prvalue_result_of (subob, TREE_OPERAND (init, 1)); >>> + return RECUR (TREE_OPERAND (init, 1)); >>> /* ??? I don't know if this can be hit. */ >>> else if (TREE_CODE (init) == PAREN_EXPR) >>> { >>> gcc_checking_assert (false); >>> - return potential_prvalue_result_of (subob, TREE_OPERAND (init, 0)); >>> + return RECUR (TREE_OPERAND (init, 0)); >>> } >>> } >>> + /* The array case listed above. */ >>> + else if (TREE_CODE (full_expr) == CONSTRUCTOR >>> + && TREE_CODE (TREE_TYPE (full_expr)) == ARRAY_TYPE) >>> + for (constructor_elt &e: CONSTRUCTOR_ELTS (full_expr)) >>> + if (e.value == subob) >>> + { >>> + *walk_subtrees = 0; >> >> Why clear walk_subtrees? Won't that mean we fail to replace any >> placeholders nested within an array element initializer? > > Right. I couldn't find a testcase where that would cause a problem > but I think I just wasn't inventive enough. > > Originally, I was checking same_type_ignoring_top_level_qualifiers_p > but that's not going to work for code like > > struct N { N(M); }; > N arr[2] = { M{""}, M{""} }; > > or with operator M(). But I suppose I could just use can_convert > like below. What do you think about that? Basing this on the type seems unreliable, we're looking for where in the expression the TARGET_EXPR occurs, and there could be others of the same type elsewhere in the expression. Why not loop over CONSTRUCTOR_ELTS like you did above, just without clearing walk_subtrees? Jason