From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id F0E763858D28; Sun, 30 Apr 2023 08:27:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0E763858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682843225; bh=r3SV98TItGu9s0CvrSL9gFRR9lpoIE/o44E2NC5slig=; h=From:To:Subject:Date:From; b=YES0gDIx8mr4TRrQHmEsVnn0YHvaM3XYI7IrG8qi2vBNsscTHGfVh8HwAuvSAu/aN WdsrqqBBZWerBcYEfQC/ZBB4cycHj5TOQTKI48QN6zkeBkO0qGUbFukorHBJ8BUY8E 7MQCm7Vr6gYP72fTEdSmEBMiBoe0W6RlzrFZfgkY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9500] coroutines: Build pointer initializers with nullptr_node [PR107768] X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 786e4fa156aa1973344af232c5370b0bc725e102 X-Git-Newrev: db0985039fa58d5ef5d4ed10d2cbfd5b3ea6b3ee Message-Id: <20230430082705.F0E763858D28@sourceware.org> Date: Sun, 30 Apr 2023 08:27:05 +0000 (GMT) List-Id: https://gcc.gnu.org/g:db0985039fa58d5ef5d4ed10d2cbfd5b3ea6b3ee commit r12-9500-gdb0985039fa58d5ef5d4ed10d2cbfd5b3ea6b3ee Author: Andrew Pinski Date: Thu Dec 8 22:34:16 2022 +0000 coroutines: Build pointer initializers with nullptr_node [PR107768] The PR reports that using integer_zero_node triggers a warning for -Wzero-as-null-pointer-constant which comes from compiler-generated code so makes no sense to the end user. Co-Authored-By: Iain Sandoe PR c++/107768 gcc/cp/ChangeLog: * coroutines.cc (coro_rewrite_function_body): Initialize pointers from nullptr_node. (morph_fn_to_coro): Likewise. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr107768.C: New test. (cherry picked from commit 0b1d66658ecdcc3d9251641a0b902b4c73ace303) Diff: --- gcc/cp/coroutines.cc | 6 +++--- gcc/testsuite/g++.dg/coroutines/pr107768.C | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 908e23597a2..71a22b5ad90 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -4135,7 +4135,7 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig, /* We will need to be able to set the resume function pointer to nullptr to signal that the coroutine is 'done'. */ tree zero_resume - = build1 (CONVERT_EXPR, resume_fn_ptr_type, integer_zero_node); + = build1 (CONVERT_EXPR, resume_fn_ptr_type, nullptr_node); /* The pointer to the destroy function. */ tree var = coro_build_artificial_var (fn_start, coro_destroy_fn_id, @@ -4522,7 +4522,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) tree ramp_body = push_stmt_list (); tree zeroinit = build1_loc (fn_start, CONVERT_EXPR, - coro_frame_ptr, integer_zero_node); + coro_frame_ptr, nullptr_node); tree coro_fp = coro_build_artificial_var (fn_start, "_Coro_frameptr", coro_frame_ptr, orig, zeroinit); tree varlist = coro_fp; @@ -4757,7 +4757,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) gcc_checking_assert (same_type_p (fn_return_type, TREE_TYPE (grooaf))); tree if_stmt = begin_if_stmt (); - tree cond = build1 (CONVERT_EXPR, coro_frame_ptr, integer_zero_node); + tree cond = build1 (CONVERT_EXPR, coro_frame_ptr, nullptr_node); cond = build2 (EQ_EXPR, boolean_type_node, coro_fp, cond); finish_if_stmt_cond (cond, if_stmt); if (VOID_TYPE_P (fn_return_type)) diff --git a/gcc/testsuite/g++.dg/coroutines/pr107768.C b/gcc/testsuite/g++.dg/coroutines/pr107768.C new file mode 100644 index 00000000000..22d7074f261 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr107768.C @@ -0,0 +1,26 @@ +// { dg-additional-options "-Wzero-as-null-pointer-constant -fsyntax-only" } + +#include + +struct task +{ + struct promise_type + { + task get_return_object() { return {}; } + std::suspend_never initial_suspend() { return {}; } + std::suspend_never final_suspend() noexcept { return {}; } + void return_void() {} + void unhandled_exception() {} + }; +}; + +task resuming_on_new_thread(void) +{ + struct awaitable + { + bool await_ready() { return false; } + void await_suspend(std::coroutine_handle<> h) { } + void await_resume() {} + }; + co_await awaitable{}; +}