From patchwork Sun Oct 3 19:52:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1535876 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=kQufHOrl; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4HMvfL4ZYKz9t0G for ; Mon, 4 Oct 2021 06:53:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC8053858022 for ; Sun, 3 Oct 2021 19:53:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC8053858022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633290790; bh=y1WfAKqF8NIG9WzGky4mcnNrn5ZiDJcHcetJ9ay9St4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kQufHOrlA8Zxwh1/HVQkgovrwzO8boNCeH68N55NEoxZ3CCVLbfkHGk8snHN8CWay LLKMSMwqxXbJulnuSc5OcrUBn9lhWDmH7AHNml8n914urD3yQUgGethJd5KwvLufCn uLYWbVd6DtI1k/CD8G0PJhez724a/wlWfBhZGNoQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 3C8FF3858D39 for ; Sun, 3 Oct 2021 19:52:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3C8FF3858D39 Received: by mail-wr1-x429.google.com with SMTP id e12so6236186wra.4 for ; Sun, 03 Oct 2021 12:52:50 -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=y1WfAKqF8NIG9WzGky4mcnNrn5ZiDJcHcetJ9ay9St4=; b=GO74iMPqtmTjEIsscBf7rAwnBfEpuCLuJBvw1HvkfRXRNidtoewsfukXGyNJ/GPBAD WjXH3VWtMbc8lRHAprdgTfOW1UQn32DZVgM1mHc8UF526Yd0G3QVgEnfG7LxuE6+sTK7 kzpHnRmKKoy6jHco78f/LSmGP+wM8jA39W6dWhD7KbMH9y0DAypo6ua46uuIC45AMTxd 0PvXasM775k7AUqO9UbAdUL+5E/nINC8vAY23PqPNXLLJiQP2tftkHvPQX8NQhCiWxdo 6ZXPoISFGGB6GsmY8c8jZzyyvDycjK5M5n0UvN4e1sM67BCo9cWLm+gZix5railDRygv DStg== X-Gm-Message-State: AOAM531s1Tj9TDUoI2Ge7C3h8R7vcAhhEyKVc4Kchjh7cVwJdyS0jRXs Xc6xQDsGWgTFTYrXcb71+/zKDz/+dM95mQ== X-Google-Smtp-Source: ABdhPJy2vSAXPzgOMv/WCDW/wVUcM8jwnRJl5rZEEW2o25M7ydBzYxLiVFa4GvnyHotJTjhi5Pp2Dw== X-Received: by 2002:a05:6000:1867:: with SMTP id d7mr8304929wri.272.1633290768612; Sun, 03 Oct 2021 12:52:48 -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 z133sm16692016wmc.45.2021.10.03.12.52.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Oct 2021 12:52:48 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] coroutines: Fix ICE with an invalid await_suspend type [PR100673]. Date: Sun, 3 Oct 2021 20:52:42 +0100 Message-Id: <20211003195242.67510-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.5 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 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" From: John Eivind Helset Hi, The reported ICE occurs when an invalid (non-template) type is found as the return for an await_suspend. Fixed by amending build_co_await to ensure that await_suspend return- type is a template-instantiation before checking to see if it is a valid coroutine handle type. Patch by John Eivind Helset, tested on x86_64, powerpc64le linux and x86_64 darwin, pushed to master as trivial/obvious, thanks Iain Signed-off-by: John Eivind Helset Signed-off-by: Iain Sandoe PR c++/100673 gcc/cp/ChangeLog: * coroutines.cc (build_co_await): Guard against NULL await_suspend types. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr100673.C: New test. --- gcc/cp/coroutines.cc | 3 ++- gcc/testsuite/g++.dg/coroutines/pr100673.C | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr100673.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index bff5b6343e5..1dd9abd1e1f 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1053,7 +1053,8 @@ build_co_await (location_t loc, tree a, suspend_point_kind suspend_kind) else if (same_type_p (susp_return_type, boolean_type_node)) ok = true; else if (TREE_CODE (susp_return_type) == RECORD_TYPE - && CLASS_TYPE_P (susp_return_type)) + && CLASS_TYPE_P (susp_return_type) + && CLASSTYPE_TEMPLATE_INFO (susp_return_type)) { tree tt = CLASSTYPE_TI_TEMPLATE (susp_return_type); if (tt == coro_handle_templ) diff --git a/gcc/testsuite/g++.dg/coroutines/pr100673.C b/gcc/testsuite/g++.dg/coroutines/pr100673.C new file mode 100644 index 00000000000..750ce66ae15 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr100673.C @@ -0,0 +1,18 @@ +// { dg-additional-options "-fsyntax-only -w" } + +// Diagnose bad coroutine awatiable type. + +#include + +struct coro{ + struct not_a_template{}; + using promise_type = coro; + static constexpr std::suspend_always initial_suspend()noexcept{ return {}; } + constexpr bool await_ready()noexcept{ return false; } + constexpr not_a_template await_suspend(std::coroutine_handle<>)noexcept{ return{}; } + constexpr void await_resume()noexcept{} + static coro body() + { + co_await coro{}; // { dg-error {'await_suspend' must return 'void', 'bool' or a coroutine handle} } + } +};