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 657773858401 for ; Tue, 12 Mar 2024 13:57:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 657773858401 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 657773858401 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=1710251859; cv=none; b=QV7K7pptnIENaWTapp8M85k3ZQicubLZ8Q9thB6cUWZXDk7hI/FN7KiJOdRRrlyE9zb8NdMJBJX9L5UyHqeqM5bqs702OgrHy94NsORMmZqmN+XEGWXtDu8ulb9a58Y7pWvfGgLK+8QCvoep3Dif/E4CWQPB+WOZAaYbBPrp63Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710251859; c=relaxed/simple; bh=LHUMLucOD5XAd9iITeUXPzHcAPGpad0mNl4wE506njA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=km6s111Na1i6D1RY/xWTPKiNb4ACgZrGlbmE97ptjwdKZytZG5gRaGUDUNtL4S3BOC13/AcMkVEq/ZIxpNbKhwSkSfZ2NXtNfwF3XMz6K6Q9DkrdB3rMt2iwU/UBJ/s5u+QqA0+uqERyXeJtviDblNEUXl6t4A7L+s2h/+FMf+g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710251857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K+XcU4eyCaWfWul5qTgp5eWUQnbUwAvq6hNZpmD1pkE=; b=Joeb/YP9L/zzxMhHf9djJ0B8lUpLeuGZ8GZYSTsMwVh26jGmX2/k4t6JcFLI+bn36Logrd mrc9mT2dKhruTwS+9aUDLhUQepfHR4dvbBD9O0eO8anYl4rzDnEkCjs0EoZOntRRHc1iZ/ XySQDW8FNqm3ZTI+d6NHOiiQIHR8XoU= Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-nMvr4MFfPPOcco1YuxuayA-1; Tue, 12 Mar 2024 09:57:35 -0400 X-MC-Unique: nMvr4MFfPPOcco1YuxuayA-1 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-3c25bf7793dso115145b6e.2 for ; Tue, 12 Mar 2024 06:57:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710251835; x=1710856635; h=content-transfer-encoding:in-reply-to:from:references: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=K+XcU4eyCaWfWul5qTgp5eWUQnbUwAvq6hNZpmD1pkE=; b=bzP5UOEMn9OsNyIeUdQ33T4urfZSpolW69c1eQw95fbVwDNWCwAsp6kr4OXLzfrULM eoUGtpqAN2rlVQkV+OjFZQKlNHmSWMWqEOOm5EX39tbzM4QExztK1CxtzrBSunkD7Elu uYyTi5EhxC5l0GWglxslpZfnxH+CBKd4gMImVYVv0h5/66GsYWvf1dHccCRI4/l6ZZEH /xzFvDfo1Xv3TfrbiRQRC9Tk+RJ5oPO0KER235aXBcnNLa/O/CDJQXcSmap6p76R6vhX u2OSWKuks5zvsm2YYZjeVW1QJVx9tNp5c9QzbSUJ2cykuTijJrXzsuNAEz7fiOEc5NYm Ptdw== X-Forwarded-Encrypted: i=1; AJvYcCUXPMYUqvZGslvC0x0U088hGhDcNZIWqdyAQKDe4cQI+dBHWpAciqZE+mGOIPCwz//QMIddC5l3+8CEolECoKtlPwQVzxOSTg== X-Gm-Message-State: AOJu0YzUK2kPv+LGMQgNbG15XRqtct7qqJcd4rc1IN+uWTOurVjl3Vu2 Y3I1jd2uxDXoBpknqNGJhtZOoPLL8Fv/OK1VGIolr5q7SQQTc4NAvZMePCFmhHlfsioQr/gD6tK /RSUOAafesgVEJ8GLRbTufnidFf7AI57BPVemAOh3SVadYlZjm1QRAmg= X-Received: by 2002:a05:6808:178c:b0:3c2:329a:ece0 with SMTP id bg12-20020a056808178c00b003c2329aece0mr4214401oib.26.1710251835652; Tue, 12 Mar 2024 06:57:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHL8MGxzw0pjBx0NwNA5zfv/C+VOR1PKgkLFrLrBLwPW173vEjkfiJ9i2P+8tgw1UDJMtpJnA== X-Received: by 2002:a05:6808:178c:b0:3c2:329a:ece0 with SMTP id bg12-20020a056808178c00b003c2329aece0mr4214387oib.26.1710251835372; Tue, 12 Mar 2024 06:57: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 r12-20020a05620a03cc00b0078874565b40sm1357380qkm.30.2024.03.12.06.57.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Mar 2024 06:57:14 -0700 (PDT) Message-ID: Date: Tue, 12 Mar 2024 09:57:14 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: ICE with temporary of class type in array DMI [PR109966] To: Marek Polacek , GCC Patches References: <20240311232758.458729-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20240311232758.458729-1-polacek@redhat.com> 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=-11.9 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,RCVD_IN_SORBS_WEB,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/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? Jason