From patchwork Mon Apr 18 15:34:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1618423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=o7iYEL2Z; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KhrbQ3TSfz9sG0 for ; Tue, 19 Apr 2022 01:34:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 985653858C27 for ; Mon, 18 Apr 2022 15:34:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 985653858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650296093; bh=OjIBHs7kL+T0lpBNP9IbmUmdE4abJESX+I9vDFxP+NI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=o7iYEL2Z9F6gq+hyNciIqhonWD/HazFmGZFqDmcIfPsoOUzrcmeI5wJBKdz6LlR9t UyYTKC+ZiFRuC8AD/YQt9fcQWd3IVqV53moVBMqrDyjwRzyNBtRSGu50fE/Um3jyK/ XaF9HsPrk7+OmHUzW965U2bgI4rl4Qek4Ll6hUVw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id B22FF3858D28 for ; Mon, 18 Apr 2022 15:34:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B22FF3858D28 Received: by mail-wr1-x42a.google.com with SMTP id bv16so1821003wrb.9 for ; Mon, 18 Apr 2022 08:34:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=OjIBHs7kL+T0lpBNP9IbmUmdE4abJESX+I9vDFxP+NI=; b=o4jHE1T0Jz4cZP/i5O5kpE32CzaX+Md1jtCW0LW7zlw+SM1f2aRrP8tWpRlbw627lE sG5dIsD3N5RXIatFw42ziaHaPe+CZFhdzfMPZdw7DTRRRyYiEVwhqMg6L7NFYFm8HQ4u qvK8DHE7CfvUFnUdtIpI+VK4SCqGBxENMDz2HjMVSixta7lnNsxwORFDuxXZ51oySRdT l8vfd49Xd4BYFT48E9WJInzNRQMQwgeWpHwcWELzHOjaNaiMjaNf3eyoR7YuroeVVBkY kPmunziSDVj3ty9I2LU8GzydNN9jYaFRMW38rpfhgdEOioeCtASmZIuZAXKKyX+bvULs /URQ== X-Gm-Message-State: AOAM5337eoHmnnE9we1j2gD7oTFOtRImaPEm4s0/LdaSmqZ2MgjHR9LK DxqaKVbSI1ZeK8p2FOuQNZY/bsiX/1A= X-Google-Smtp-Source: ABdhPJw0ZnwIbM421EfFi61xWhNFh71WHzeJZzaj0s15333B5/NXMCF2brstTWeBglC4greUNiCMwg== X-Received: by 2002:adf:c10b:0:b0:1ed:c40f:7f91 with SMTP id r11-20020adfc10b000000b001edc40f7f91mr8561127wre.276.1650296051486; Mon, 18 Apr 2022 08:34:11 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id az20-20020a05600c601400b0038ffb253bb3sm13674557wmb.36.2022.04.18.08.34.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Apr 2022 08:34:10 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, coroutines: Improve check for throwing final await [PR104051]. Date: Mon, 18 Apr 2022 16:34:04 +0100 Message-Id: <20220418153404.71282-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We check that the final_suspend () method returns a sane type (i.e. a class or structure) but, unfortunately, that check has to be later than the one for a throwing case. If the user returns some nonsensical type from the method, we need to handle that in the checking for noexcept. tested on x86_64-darwin, OK for mainline? (when?), thanks Iain Signed-off-by: Iain Sandoe PR c++/104051 gcc/cp/ChangeLog: * coroutines.cc (coro_diagnose_throwing_final_aw_expr): Handle non-target expression inputs. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr104051.C: New test. --- gcc/cp/coroutines.cc | 13 +++++----- gcc/testsuite/g++.dg/coroutines/pr104051.C | 29 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr104051.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index d2a765cac11..cb9bbed51e6 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -883,13 +883,14 @@ coro_diagnose_throwing_fn (tree fndecl) static bool coro_diagnose_throwing_final_aw_expr (tree expr) { - tree t = TARGET_EXPR_INITIAL (expr); + if (TREE_CODE (expr) == TARGET_EXPR) + expr = TARGET_EXPR_INITIAL (expr); tree fn = NULL_TREE; - if (TREE_CODE (t) == CALL_EXPR) - fn = CALL_EXPR_FN(t); - else if (TREE_CODE (t) == AGGR_INIT_EXPR) - fn = AGGR_INIT_EXPR_FN (t); - else if (TREE_CODE (t) == CONSTRUCTOR) + if (TREE_CODE (expr) == CALL_EXPR) + fn = CALL_EXPR_FN (expr); + else if (TREE_CODE (expr) == AGGR_INIT_EXPR) + fn = AGGR_INIT_EXPR_FN (expr); + else if (TREE_CODE (expr) == CONSTRUCTOR) return false; else { diff --git a/gcc/testsuite/g++.dg/coroutines/pr104051.C b/gcc/testsuite/g++.dg/coroutines/pr104051.C new file mode 100644 index 00000000000..ce7ae55405a --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr104051.C @@ -0,0 +1,29 @@ +// { dg-additional-options "-fsyntax-only" } +#include +#include +template struct promise { + struct final_awaitable { + bool await_ready() noexcept; + template + std::coroutine_handle<> + await_suspend(std::coroutine_handle) noexcept; + void await_resume() noexcept; + }; + auto get_return_object() { + return std::coroutine_handle::from_promise(*this); + } + auto initial_suspend() { return std::suspend_always(); } + auto final_suspend() noexcept { return true; } + void unhandled_exception(); +}; +template struct task { + using promise_type = promise; + task(std::coroutine_handle>); + bool await_ready(); + std::coroutine_handle<> await_suspend(std::coroutine_handle<>); + T await_resume(); +}; +task> foo() { // { dg-error {awaitable type 'bool' is not a structure} } + while ((co_await foo()).empty()) + ; +}