From patchwork Tue Aug 6 14:01:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1969591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Vi7Uvx7W; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WdZjq4Tztz1ydt for ; Wed, 7 Aug 2024 00:01:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77D043858289 for ; Tue, 6 Aug 2024 14:01:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 84AEC385B508 for ; Tue, 6 Aug 2024 14:01:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84AEC385B508 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 84AEC385B508 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=1722952890; cv=none; b=vD+44bMiGabYfjrGUAUsRkA2qQQRwe7cLdAq6EaAIi/VKlmEg4hO1aSGCT/+fLWdoT9NAuzfb+5nIFWQJCX9zHHjdhqxUZ2fRNtbGdeqfs80m63QVgnU/IXD7MNV3RNcIr1P3bVqxRJmhGB1Q2gkEfUPaBceku/lDnQRA/2aEfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722952890; c=relaxed/simple; bh=2L7vOGjNm7Vmvz3bDpLQ6XLn/9OAc5NnRoStt8G2ohs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nNcHqdwebEYxNkR4TRnSFANHRkqufNtn2BUUzy9s5St57Bw0C399mT3rZuumJE2ahxHuk20m4eaIlhUsxvQ4GlcxTIGes/EB5bYKpBwFklrzh7c405UAbajGgypvLkEO0g+nnP9mgEICCnNptPR1fNMwNGxUtGVheZk4aH+BHio= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722952888; 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; bh=CaUd4MxkhLV4fFBLME2YEjBkh/8N8DOVbo2/LQKYrD4=; b=Vi7Uvx7W14705nqdi0Gx/sF2fag2TX5belSRBKDGkmjlLLf2EqIdclWjWKwK3E45e+bIP8 /yldRzUTimdJstztRzFnOzlhikhR7sqtttaQ8h9W0lgSlWdJoN5Fe1oJcT8+Y7XkRz6Vw1 TgLT39RM2nezJ9+TsM5Le3jjzvZ+JU0= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-322-FvE-5zMfMsSt-7sVQMvl2g-1; Tue, 06 Aug 2024 10:01:27 -0400 X-MC-Unique: FvE-5zMfMsSt-7sVQMvl2g-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7a2028bae15so101885485a.0 for ; Tue, 06 Aug 2024 07:01:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722952885; x=1723557685; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CaUd4MxkhLV4fFBLME2YEjBkh/8N8DOVbo2/LQKYrD4=; b=Bs+xiONkLwX5larR0xl6Iq8WqEolqfJrVHs8wAwjO2jP3nA6xgTf67YyP5Umig4xk4 tCEl1rjs0bXTyIaU5R7xBz0w3wA+PmGsy5+DIjUNjWCgSzg1jP7/EFQ42rMnke+EUlxP t21EtO6DL7yIAJXOvLMSSUfmdLJbCBwTqBHXQb37IAzyJfQXVMdyklXc3N9tlZzEWNAV l91cIsacCI/kgk1pItRmniLeqpDs42yJwCvaDnwyMqxhoREkS0ei6OdLcRA/2L6YNEyG VD3GXJ+Bwslpmxsy7wb82ViDLw6rrAmloPS8pGNwdEy1qLpoPQEGvAvUDB9P150r+G0b 5JLQ== X-Gm-Message-State: AOJu0YwFQcSgyQ2Sn7lFwU26/JqNBBAIjoN7XdqtBZi+qX2dz9kU3QOi 8q9ivWw7vocDsJAh+BhCJVVOlR320Y+Ps5pmi0YycLiihACG6Y2O43noyllEdWO8N4dzHD+WVhX zzuu0RE0Bu7U1LE72E4l9q8CsmY0tzLKv03Mx9wUcJxYsb7I8jtaORSUMhylW4P+S36zc+FPaMK 9iepU2PnCo01kZUxmFMa77A5ntQbn0VOGgwHO3 X-Received: by 2002:a05:620a:45a6:b0:7a2:c6f:fa3f with SMTP id af79cd13be357-7a34efc2dbbmr2018423385a.50.1722952885281; Tue, 06 Aug 2024 07:01:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFKFrUb/yQVk8TH2MSpkqOHBQyLAC8XCPavlqYNMjd7TuneBNmCd8zER10Wb3Urq4DRwAYfg== X-Received: by 2002:a05:620a:45a6:b0:7a2:c6f:fa3f with SMTP id af79cd13be357-7a34efc2dbbmr2018419385a.50.1722952884710; Tue, 06 Aug 2024 07:01:24 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a34f7860cdsm458298785a.101.2024.08.06.07.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 07:01:24 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: fold calls to std::forward_like [PR96780] Date: Tue, 6 Aug 2024 10:01:22 -0400 Message-ID: <20240806140122.144017-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.0.39.g891ee3b9db MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- This extends our folding of cast-like standard library functions to also include C++23's std::forward_like. PR c++/96780 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold) : Fold calls to std::forward_like as well. gcc/testsuite/ChangeLog: * g++.dg/opt/pr96780.C: Test std::forward_like folding. Reviewed-by: Marek Polacek --- gcc/cp/cp-gimplify.cc | 3 ++- gcc/testsuite/g++.dg/opt/pr96780.C | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index b88c3b7f370..3db9657ae93 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -3316,7 +3316,8 @@ cp_fold (tree x, fold_flags_t flags) || id_equal (DECL_NAME (callee), "addressof") /* This addressof equivalent is used heavily in libstdc++. */ || id_equal (DECL_NAME (callee), "__addressof") - || id_equal (DECL_NAME (callee), "as_const"))) + || id_equal (DECL_NAME (callee), "as_const") + || id_equal (DECL_NAME (callee), "forward_like"))) { r = CALL_EXPR_ARG (x, 0); /* Check that the return and argument types are sane before diff --git a/gcc/testsuite/g++.dg/opt/pr96780.C b/gcc/testsuite/g++.dg/opt/pr96780.C index 61e11855eeb..a29cda8b836 100644 --- a/gcc/testsuite/g++.dg/opt/pr96780.C +++ b/gcc/testsuite/g++.dg/opt/pr96780.C @@ -29,6 +29,10 @@ void f() { auto&& x11 = std::as_const(a); auto&& x12 = std::as_const(ca); #endif +#if __cpp_lib_forward_like + auto&& x13 = std::forward_like(a); + auto&& x14 = std::forward_like(ca); +#endif } // { dg-final { scan-tree-dump-not "= std::move" "gimple" } } @@ -36,3 +40,4 @@ void f() { // { dg-final { scan-tree-dump-not "= std::addressof" "gimple" } } // { dg-final { scan-tree-dump-not "= std::__addressof" "gimple" } } // { dg-final { scan-tree-dump-not "= std::as_const" "gimple" } } +// { dg-final { scan-tree-dump-not "= std::forward_like" "gimple" } }