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.129.124]) by sourceware.org (Postfix) with ESMTPS id 591DF3858D33 for ; Fri, 24 May 2024 00:32:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 591DF3858D33 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 591DF3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716510767; cv=none; b=Qc/AuiwFTcWKVRtyWe8+uPN0cENP3aQxooT7LKppGYdZRI6K3FRdJnNhJ//KbbQ/V7olMISHf5fz2I9hfG7VIlP4f37KP8ZS4jfLeqv6NP4YwHeD+AgcMuyVY7vtv6a/7D42I4bF0cWMR6AAaiaGI6ZpkH/tBrReXDP1S3p9b04= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716510767; c=relaxed/simple; bh=a1aeyv0/Mi2Xw9ByWFaxDtaIuWwFywURbdF6Uw4thZA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=wWzo5OcFdSgNrhjyRIbrfPoWNSs/JgMMtXK9xpVAwdsi33DD0i4uhDNBBhTw6J/BNSRSdQyfD7lXtHnbxjYA+4Ux3fsV1PssZbZIOWxoBCfdLSBQDDpLWi1fj9EMMJaXkR4y+/7rAwhmwyk/R7MZAvYta2CSI0eLeA81lsI2UvE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716510765; 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: in-reply-to:in-reply-to:references:references; bh=I/MmN38nS9hV1/cXNX66F5AsNHTTJsmmzZa24aL70mg=; b=iZdiX/nt9YqcA/TQKjv8e3Rs8jlVbs9dbSdqx0F8gDkmKVFWGNPCnsxv0En8rf171DwNe3 H6as7SY2AzBrNIfmU1G1Dm86KQbdDJStLBAUaRyJQCagWswWsS1JX8jFWy3vvsJ0gp9F/D tNFiJ7dHJj+VivQZRjPk3ceyxguEb3M= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-1SByzJQjP1SKvpj7xTF9ug-1; Thu, 23 May 2024 20:32:43 -0400 X-MC-Unique: 1SByzJQjP1SKvpj7xTF9ug-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7949746f564so71062685a.1 for ; Thu, 23 May 2024 17:32:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716510762; x=1717115562; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I/MmN38nS9hV1/cXNX66F5AsNHTTJsmmzZa24aL70mg=; b=L+tGhyMmw1wHOe+X4pXlQp4DrGXJxgGY/Xta32HOSpLjw4zEZabs8FRnpqHT+nob/Q Z2ApekRRRzkIoSw2Sy4w4osbQNCYpQGjUe8UCNQTfZuEMs2yMqRUhC0/4devp4c5Phmn pvuvJWkfOB30KEuM8K5MPdNoCMwGsTXVeqtzXoDUjnigyYBXwZopMRPDkVWpDT1KLEb0 QovQMY517BGyKN2h6ipjiCihGnuvUtLSrtbPbO33Ba4IF+fDRFGin3L09lpykjHtMIUQ vtU7UH/K3GRTzsHWVGtxpk8P+rQI3jsZDVRK+WFBZ4bnfGPVwqzT8cx9rFJZWDWK3m1S DMdQ== X-Gm-Message-State: AOJu0YwsxQGXw9yLPX8ALZTJ3LGDwx4chOaiQZXLopjBygoA/HBp2Y3X 466/yW0oDoGUCf+wNJY4yfgSI4lSOg2SHmHm+vs2nPcbdS7e30rUK9cTwpMgRW0TKlCdJsOtecr Ot4XNS7pLRnML+6weSLX7AwntMgFrFHJkECp4Z1++04YV2q0zjG/7b2c= X-Received: by 2002:a05:620a:460e:b0:790:f696:2eb0 with SMTP id af79cd13be357-794ab1125ccmr90965585a.75.1716510762442; Thu, 23 May 2024 17:32:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGw3T2jSUqzzcKEk56hAW3dQDSlq8sPQtcse2hsfEsFg0++o/spWq9tS1YvmzlD+AIMI860gQ== X-Received: by 2002:a05:620a:460e:b0:790:f696:2eb0 with SMTP id af79cd13be357-794ab1125ccmr90963385a.75.1716510761808; Thu, 23 May 2024 17:32:41 -0700 (PDT) Received: from redhat.com ([2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abcbfd0asm14793285a.37.2024.05.23.17.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 17:32:41 -0700 (PDT) Date: Thu, 23 May 2024 20:32:39 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: [PATCH v2] c++: mark TARGET_EXPRs for function arguments eliding [PR114707] Message-ID: References: <20240523144145.15177-1-polacek@redhat.com> <4bff239a-0437-488d-a295-09e218d4cb8d@redhat.com> MIME-Version: 1.0 In-Reply-To: <4bff239a-0437-488d-a295-09e218d4cb8d@redhat.com> User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP 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 Thu, May 23, 2024 at 04:04:13PM -0400, Jason Merrill wrote: > On 5/23/24 10:41, Marek Polacek wrote: > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > -- >8 -- > > Coming back to our discussion in > > : > > TARGET_EXPRs that initialize a function argument are not marked > > TARGET_EXPR_ELIDING_P even though gimplify_arg drops such TARGET_EXPRs > > on the floor. > > But only if TREE_TYPE (TARGET_EXPR_INITIAL is non-void, I think we should > check that here too to be parallel. Ah yes, definitely. > Perhaps most/all affected TARGET_EXPRs will have been handled earlier in the > function under the TREE_ADDRESSABLE check, but I wouldn't rely on that > without an assert. So like this or you want an assert somewhere too? dg.exp passed. -- >8 -- Coming back to our discussion in : TARGET_EXPRs that initialize a function argument are not marked TARGET_EXPR_ELIDING_P even though gimplify_arg drops such TARGET_EXPRs on the floor. To work around it, I added a pset to replace_placeholders_for_class_temp_r, but it would be best to just rely on TARGET_EXPR_ELIDING_P. PR c++/114707 gcc/cp/ChangeLog: * call.cc (convert_for_arg_passing): Call set_target_expr_eliding. * typeck2.cc (replace_placeholders_for_class_temp_r): Don't use pset. (digest_nsdmi_init): Call cp_walk_tree_without_duplicates instead of cp_walk_tree. --- gcc/cp/call.cc | 6 ++++++ gcc/cp/typeck2.cc | 20 ++++---------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index ed68eb3c568..35c024f2c7c 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -9437,6 +9437,12 @@ convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain) if (complain & tf_warning) warn_for_address_of_packed_member (type, val); + /* gimplify_arg elides TARGET_EXPRs that initialize a function argument. */ + if (TREE_CODE (val) == TARGET_EXPR) + if (tree init = TARGET_EXPR_INITIAL (val)) + if (!VOID_TYPE_P (TREE_TYPE (init))) + set_target_expr_eliding (val); + return val; } diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index 06bad4d3303..7782f38da43 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -1409,16 +1409,14 @@ digest_init_flags (tree type, tree init, int flags, tsubst_flags_t complain) in the context of guaranteed copy elision). */ static tree -replace_placeholders_for_class_temp_r (tree *tp, int *, void *data) +replace_placeholders_for_class_temp_r (tree *tp, int *, void *) { tree t = *tp; - auto pset = static_cast *>(data); /* We're looking for a TARGET_EXPR nested in the whole expression. */ if (TREE_CODE (t) == TARGET_EXPR /* That serves as temporary materialization, not an initializer. */ - && !TARGET_EXPR_ELIDING_P (t) - && !pset->add (t)) + && !TARGET_EXPR_ELIDING_P (t)) { tree init = TARGET_EXPR_INITIAL (t); while (TREE_CODE (init) == COMPOUND_EXPR) @@ -1433,16 +1431,6 @@ replace_placeholders_for_class_temp_r (tree *tp, int *, void *data) gcc_checking_assert (!find_placeholders (init)); } } - /* TARGET_EXPRs initializing function arguments are not marked as eliding, - even though gimplify_arg drops them on the floor. Don't go replacing - placeholders in them. */ - else if (TREE_CODE (t) == CALL_EXPR || TREE_CODE (t) == AGGR_INIT_EXPR) - for (int i = 0; i < call_expr_nargs (t); ++i) - { - tree arg = get_nth_callarg (t, i); - if (TREE_CODE (arg) == TARGET_EXPR && !TARGET_EXPR_ELIDING_P (arg)) - pset->add (arg); - } return NULL_TREE; } @@ -1490,8 +1478,8 @@ digest_nsdmi_init (tree decl, tree init, tsubst_flags_t complain) temporary materialization does not occur when initializing an object from a prvalue of the same type, therefore we must not replace the placeholder with a temporary object so that it can be elided. */ - hash_set pset; - cp_walk_tree (&init, replace_placeholders_for_class_temp_r, &pset, nullptr); + cp_walk_tree_without_duplicates (&init, replace_placeholders_for_class_temp_r, + nullptr); return init; } base-commit: ee492101c2e51b58e926307448d35f539aec0b2c -- 2.45.1