From patchwork Wed Aug 28 19:59:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Arsen_Arsenovi=C4=87?= X-Patchwork-Id: 1978050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aarsen.me header.i=@aarsen.me header.a=rsa-sha256 header.s=MBO0001 header.b=Wu0XRr5/; 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 4WvGCg0sw5z1yfy for ; Thu, 29 Aug 2024 06:26:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FBAC385DDF1 for ; Wed, 28 Aug 2024 20:26:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id F3CEE3858D39 for ; Wed, 28 Aug 2024 20:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3CEE3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F3CEE3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.241.56.171 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724876775; cv=none; b=MYUK7dHdnlIhg5VT52fEBaPMq2qR64JIzuCM8UnTFd0Y+sLjV1fU9hb7XVcn5Fw5XZM9BgHsLvPGtaxg9+Cbu4PJrp4rDztmQKG2z5NgpZnRoVJcs401Ft0Lhc3uTCg8RcxgB5AFwb1KyfVgK0vFLIlwKF4hqE9G0TBRAcvrtA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724876775; c=relaxed/simple; bh=VThDVBGg7vNS1khB2XPBSHGinSOHRsEygOk5ag5irP0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bdWF6IEPeIUik4m+nyCaWn284Xy9Cr0gm/F6B6YbWoqU91pyspFKT6dm+RWGsxkwcqCi4e+fCtJOCpOWmZL1ryvnZcK3qn85kLNud8+yOIxVWx4Tw0Fi6H9oWvxDrJcjrYntmUTZn83luqig73XWIxsk26XXRepFnEvvTrAs7vA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4WvGC61kS2z9t2h; Wed, 28 Aug 2024 22:26:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1724876770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yljnGBNAI16D5bcvyGQGd+bJP5jkFiUemGw0tjOzB9s=; b=Wu0XRr5/78BQVGRYEwo1NvOLXdP9kQJTl+YblIsgNvbdyMRdf9usH7XI60LJx9T4mdEDR1 /jerbdgIbS/Aw5dzurS0C9oymlmr+RsYjwn8X3b6Y3Z0GYMDq/LvwosOKk6M8NQTqL819P KPyx55I+4ivBOoDOs0MnO/H6PKtlEPItMWNrFr5ttlMtwuo/NSUja9tecfV3woRMkVQT/q pxQKZEKMnFcFVFDsiJv7Vy9SlJx+1ENViVFtKhC7FHx78eNrsiJyK+CI0BE7VParTUB/sV ZxmC0ndLtl3SwDGyZHJ5ZG1iJfH5rBwuY4T4YGKws7wy2BSQDwJp44tacqfOjg== From: =?utf-8?q?Arsen_Arsenovi=C4=87?= To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?Arsen_Arsenovi=C4=87?= , Jason Merrill , Iain Sandoe Subject: [PATCH 1/3] c++: stop altering co_awaits converted to void Date: Wed, 28 Aug 2024 21:59:16 +0200 Message-ID: <20240828202119.17640-2-arsen@aarsen.me> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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 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 This patch fixes a gcc-15 regression (PR116502) and an inelegance in my earlier patch related to converting CO_AWAIT_EXPRs to void. This wasn't noticed anywhere AFAICT, but it was a bit unfortunate. The other two patches fix an actual regression as well as provide handling for converting INDIRECT_REFs wrapping CO_AWAIT_EXPRs (which I noticed was lacking while triaging the regression). WRT INDIRECT_REFs, I've considered making convert_to_void recurse on the INDIRECT_REF case, so that special handling doesn't need to be added when some expression might end up getting wrapped in a INDIRECT_REF. Is there a reason why we don't do that? I've started a regstrap with that recursion added in order to see whether it is something to possibly explore. The change being regstrapped looks like so: diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index ce26cb8ef30..8f874f4f4dc 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -1432,11 +1432,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) && !is_reference) warning_at (loc, OPT_Wunused_value, "value computed is not used"); expr = TREE_OPERAND (expr, 0); - if (TREE_CODE (expr) == CALL_EXPR - && (complain & tf_warning)) - maybe_warn_nodiscard (expr, implicit); - else if (TREE_CODE (expr) == CO_AWAIT_EXPR) - convert_co_await_to_void (expr, implicit, complain); + return convert_to_void (expr, implicit, complain); } break; At any rate, the patchset was tested as-is on x86_64-pc-linux-gnu also. If the above shouldn't be done for whatever reason, is the current set OK for trunk? TIA, have a lovely evening. ---------- >8 ---------- As of r15-2318-g2664c1bf83855b, we started altering co_await expressions cast to void so that their constituent await-resume expression is also cast to void. This leads to the TREE_TYPE of the CO_AWAIT_EXPR being wrong, because it should be the same as the await-resume expression, but it ended up being void. While this appears not to cause trouble currently, it could induce bugs in the future, without being necessary. gcc/cp/ChangeLog: * coroutines.cc (co_await_get_resume_call): Don't return a pointer to the await-resume expression. * cp-tree.h (co_await_get_resume_call): Change return type to a non-pointer 'tree'. * cvt.cc (convert_to_void): Adjust according to the above. --- gcc/cp/coroutines.cc | 4 ++-- gcc/cp/cp-tree.h | 2 +- gcc/cp/cvt.cc | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index f243fe9adae2..166978ab464b 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -728,14 +728,14 @@ coro_get_destroy_function (tree decl) /* Given a CO_AWAIT_EXPR AWAIT_EXPR, return its resume call. */ -tree* +tree co_await_get_resume_call (tree await_expr) { gcc_checking_assert (TREE_CODE (await_expr) == CO_AWAIT_EXPR); tree vec = TREE_OPERAND (await_expr, 3); if (!vec) return nullptr; - return &TREE_VEC_ELT (vec, 2); + return TREE_VEC_ELT (vec, 2); } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 2eeb5e3e8b16..417ed4919c39 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8776,7 +8776,7 @@ extern tree coro_get_actor_function (tree); extern tree coro_get_destroy_function (tree); extern tree coro_get_ramp_function (tree); -extern tree* co_await_get_resume_call (tree await_expr); +extern tree co_await_get_resume_call (tree await_expr); /* contracts.cc */ diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index 7b4bd8a9dc44..b6b35ef9cacf 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -1505,8 +1505,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) case CO_AWAIT_EXPR: { auto awr = co_await_get_resume_call (expr); - if (awr && *awr) - *awr = convert_to_void (*awr, implicit, complain); + if (awr) + awr = convert_to_void (awr, implicit, complain); break; }