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; } From patchwork Wed Aug 28 19:59:17 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: 1978051 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=NYVq8Okb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WvGCg5v1pz1yg5 for ; Thu, 29 Aug 2024 06:26:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7994385ED71 for ; Wed, 28 Aug 2024 20:26:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050:0:465::202]) by sourceware.org (Postfix) with ESMTPS id A38993858402 for ; Wed, 28 Aug 2024 20:26:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A38993858402 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 A38993858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2050:0:465::202 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724876778; cv=none; b=FfuM0xn8SyKiTTd4/JbSlDLvnUHETHu+h9YAluhast8K0YyI71FEHdH2sQ6hB5XTQQuTpfXf+7QUp/0HYYgws3GZ7eK1CXU2z01GI4R186GKI+tUdhnJBNv7P+8uap3nbIg4P82WkPouA2Xexgd6DP0RIvz9OvxHvWWtad+ozLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724876778; c=relaxed/simple; bh=Wktcrqj5OHK9pPVKex4soYMiNGfZEmE5+iVVfheWF58=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GE4+x2z55+40HrzLuIOa3UjMq5SrqmLAp69TDJ/9jyI5OjZs9rS6FluazZeLV/O9rPC6wH4N+SMhVkzH9TI61wISSAG02xepE/M4lvOqYeLihFe9WGSwI+JUycVx05hbr95+gujCZTB9q14+e6I1QyZ9SQCePGt+7UgZMxKHNWk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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-202.mailbox.org (Postfix) with ESMTPS id 4WvGC73rZxz9spc; Wed, 28 Aug 2024 22:26:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1724876771; 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: in-reply-to:in-reply-to:references:references; bh=Bn5vcpHRxsLSYn6ZA5EIzdUdpk7x2bTZtz/E68Sm6OI=; b=NYVq8Okb14dP2+C+fMGOGvL7zGSWg6bFs75huFzSqeFerVWNhecqbyp9KswWzxoc6Ee114 IIhNzQ+Hs3xjpnZGFvpTPUwhmrrzQUHN2YMHqy75dUbMzzVkziJ9m0oLEnPENLj/0BwSvj UJecSdSq/aV7mpTDdI3oDspNnru7GnMwkv2vmNCb2JuPidDuRms7oV5ENwRSOBp76ISQWU zgtjXu4i33BLmjHz3F558GO4kXsqSVlnN2DE5LDWqWtNCsZkt6X7yMIxKpM+lIm/GQORvn Uk2HsHZL/j+id9FWRbp6567QiYX5dEhii9cuhPTVM9gxunSL9RKzV9NFqJ0Iiw== 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 2/3] c++: handle CO_AWAIT_EXPRs wrapped in INDIRECT_REF Date: Wed, 28 Aug 2024 21:59:17 +0200 Message-ID: <20240828202119.17640-3-arsen@aarsen.me> In-Reply-To: <20240828202119.17640-2-arsen@aarsen.me> References: <20240828202119.17640-2-arsen@aarsen.me> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4WvGC73rZxz9spc X-Spam-Status: No, score=-11.1 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 Currently, GCC misses a diagnostic when discarding a CO_AWAIT_EXPR resulting in a reference type, because such an expression is wrapped in an INDIRECT_REF in finish_co_await_expr. Similar handling is necessary for CALL_EXPRs, so extend it to also handle CO_AWAIT_EXPR. gcc/cp/ChangeLog: * cvt.cc (convert_co_await_to_void): New function. Extracted from the convert_to_void CO_AWAIT_EXPR case for reuse in the INDIRECT_REF case. (convert_to_void) : If met with a CO_AWAIT_EXPR, call convert_co_await_to_void on it. : Use new helper. --- gcc/cp/cvt.cc | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index b6b35ef9cacf..ce26cb8ef30f 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -1139,6 +1139,20 @@ maybe_warn_nodiscard (tree expr, impl_conv_void implicit) } } +/* Converts the await-resume of a given co_await expr to void. This is useful + because the await-resume expression is the result of the entire + co_await, so discarding the result of a co_await is the same as discarding + the result of its await-resume expr. */ + +void +convert_co_await_to_void (tree expr, impl_conv_void implicit, + tsubst_flags_t complain) +{ + auto awr = co_await_get_resume_call (expr); + if (awr) + convert_to_void (awr, implicit, complain); +} + /* When an expression is used in a void context, its value is discarded and no lvalue-rvalue and similar conversions happen [expr.static.cast/4, stmt.expr/1, expr.comma/1]. This permits dereferencing an incomplete type @@ -1421,6 +1435,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) 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); } break; @@ -1503,12 +1519,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) break; case CO_AWAIT_EXPR: - { - auto awr = co_await_get_resume_call (expr); - if (awr) - awr = convert_to_void (awr, implicit, complain); - break; - } + convert_co_await_to_void (expr, implicit, complain); + break; default:; } From patchwork Wed Aug 28 19:59:18 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: 1978049 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=SHLoIGKS; 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 4WvGCg1brRz1yg0 for ; Thu, 29 Aug 2024 06:26:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0966F385EC55 for ; Wed, 28 Aug 2024 20:26:36 +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 B14EC3858C31 for ; Wed, 28 Aug 2024 20:26:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B14EC3858C31 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 B14EC3858C31 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=1724876777; cv=none; b=s1Bs+HaemYQBl26/17Gl0SpgBsJDvDF23hDg79OuaQckjz/539+qY26PXU1tDKltbvS35OGBJ5AmJF7k2gLb3XNmd0Z5ES9MNEZs7a8c0uYsDS5FZUkzLNgCpE74TAvZusSjizJfE3rygW1CtWC+yf8E4mXUHMx7Q0OAwcckkDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724876777; c=relaxed/simple; bh=BZy2y8+XlkhhoiEnA8yHS48a1pemNAuB3ZlIb+v8YVI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SjrkIhBlan0a1DfmhqpzNSvPB7C19xqNWW/IuKKITyRAQaZHy4XxAVp4Wp12KpvQurzZygNgQhzyS0bWCFjFKuPpkKCRWeg4rh3J3eBHNwzfaVKD2Zc1CU/jRn523499dnECeoC9NCFz7AS24FKVQ6YiF5hOsL8Tmm9iBt3n8jI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 4WvGC85T9Wz9t33; Wed, 28 Aug 2024 22:26:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1724876772; 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: in-reply-to:in-reply-to:references:references; bh=IfHorplP4TyGzds6S3DWycDAL4nOUqMH6PunGSocCuQ=; b=SHLoIGKSGkipyeN/PRIj6cIVVfCqVcm7kEWJ2WTBZg6LzWnrzgK92KdWCCT5MOnvHViCqL EA6LyZB7+P8RARTcw+6ZWbIKWPB2O3jNB5MxpbjvtV1YReN4peoCH3gIKqGCn4atjsVJ0C bW6w7MNuvabLxNqWrSneUm1eWajb1TdEu9LeHiGIYyyQ1rZ7ce0YsGOGqNk3tZJpRljV2T wVqcXdYt4JXInsdob4FQrHc3nVn7SdXqDV5rQ55Hm6zYo8AXj5BUi7sXgBeE+B3jAp9pEM RuD7qnLbLm6jfQTqedetDzEbDT8sDd4Cjb2/fz+2oOz8WPUCTzP9Ooz2XfvmKg== 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 3/3] c++/coro: prevent ICV_STATEMENT diagnostics in temp promotion [PR116502] Date: Wed, 28 Aug 2024 21:59:18 +0200 Message-ID: <20240828202119.17640-4-arsen@aarsen.me> In-Reply-To: <20240828202119.17640-2-arsen@aarsen.me> References: <20240828202119.17640-2-arsen@aarsen.me> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4WvGC85T9Wz9t33 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, KAM_SHORT, 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 Hm, maybe-unused-1.C should be moved into the previous patch. Could do before pushing. ---------- >8 ---------- If such a diagnostic is necessary, it has already been emitted, otherwise, it is not correct and emitting it here is inactionable by the user, and bogus. PR c++/116502 gcc/cp/ChangeLog: * coroutines.cc (maybe_promote_temps): Convert temporary initializers to void without complaining. gcc/testsuite/ChangeLog: * g++.dg/coroutines/maybe-unused-1.C: New test. * g++.dg/coroutines/pr116502.C: New test. --- gcc/cp/coroutines.cc | 12 +++++-- .../g++.dg/coroutines/maybe-unused-1.C | 33 +++++++++++++++++++ gcc/testsuite/g++.dg/coroutines/pr116502.C | 33 +++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/maybe-unused-1.C create mode 100644 gcc/testsuite/g++.dg/coroutines/pr116502.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 166978ab464b..780dc506825b 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -3147,7 +3147,13 @@ maybe_promote_temps (tree *stmt, void *d) to run the initializer. If the initializer is a conditional expression, we need to collect and declare any promoted variables nested within it. DTORs for such - variables must be run conditionally too. */ + variables must be run conditionally too. + + Since here we're synthetically processing code here, we've already + emitted any Wunused-result warnings. Below, however, we call + finish_expr_stmt, which will convert its operand to void, and could + result in such a diagnostic being emitted. To avoid that, convert to + void ahead of time. */ if (t->var) { tree var = t->var; @@ -3157,7 +3163,7 @@ maybe_promote_temps (tree *stmt, void *d) if (TREE_CODE (t->init) == COND_EXPR) process_conditional (t, vlist); else - finish_expr_stmt (t->init); + finish_expr_stmt (convert_to_void (t->init, ICV_STATEMENT, tf_none)); if (tree cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error)) { tree cl = build_stmt (sloc, CLEANUP_STMT, expr_list, cleanup, var); @@ -3176,7 +3182,7 @@ maybe_promote_temps (tree *stmt, void *d) if (TREE_CODE (t->init) == COND_EXPR) process_conditional (t, vlist); else - finish_expr_stmt (t->init); + finish_expr_stmt (convert_to_void (t->init, ICV_STATEMENT, tf_none)); if (expr_list) { if (TREE_CODE (expr_list) != STATEMENT_LIST) diff --git a/gcc/testsuite/g++.dg/coroutines/maybe-unused-1.C b/gcc/testsuite/g++.dg/coroutines/maybe-unused-1.C new file mode 100644 index 000000000000..68d59d83e8eb --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/maybe-unused-1.C @@ -0,0 +1,33 @@ +// https://gcc.gnu.org/PR116502 +#include + +struct SuspendNever { + bool await_ready() noexcept; + void await_suspend(std::coroutine_handle<>) noexcept; + void await_resume() noexcept; +}; + +struct Coroutine; + +struct PromiseType { + Coroutine get_return_object(); + SuspendNever initial_suspend(); + SuspendNever final_suspend() noexcept; + void return_void(); + void unhandled_exception(); +}; + +struct Coroutine { + using promise_type = PromiseType; +}; + +struct Awaiter { + bool await_ready(); + void await_suspend(std::coroutine_handle<>); + [[nodiscard]] int& await_resume(); +}; + +Coroutine foo() +{ + co_await Awaiter {}; // { dg-warning "Wunused-result" } +} diff --git a/gcc/testsuite/g++.dg/coroutines/pr116502.C b/gcc/testsuite/g++.dg/coroutines/pr116502.C new file mode 100644 index 000000000000..95cc0bc8a983 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr116502.C @@ -0,0 +1,33 @@ +// https://gcc.gnu.org/PR116502 +#include + +struct SuspendNever { + bool await_ready() noexcept; + void await_suspend(std::coroutine_handle<>) noexcept; + void await_resume() noexcept; +}; + +struct Coroutine; + +struct PromiseType { + Coroutine get_return_object(); + SuspendNever initial_suspend(); + SuspendNever final_suspend() noexcept; + void return_void(); + void unhandled_exception(); +}; + +struct Coroutine { + using promise_type = PromiseType; +}; + +struct Awaiter { + bool await_ready(); + void await_suspend(std::coroutine_handle<>); + [[nodiscard]] int& await_resume(); +}; + +Coroutine foo() +{ + (void)co_await Awaiter {}; +}