coroutines: Build pointer initializers with nullptr_node [PR107768]
authorAndrew Pinski <pinskia@gmail.com>
Thu, 8 Dec 2022 22:34:16 +0000 (22:34 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 16 Dec 2022 20:15:59 +0000 (20:15 +0000)
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 <iain@sandoe.co.uk>
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.

gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr107768.C [new file with mode: 0644]

index 3f23317..88d6c30 100644 (file)
@@ -4132,7 +4132,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,
@@ -4519,7 +4519,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;
@@ -4754,7 +4754,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 (file)
index 0000000..22d7074
--- /dev/null
@@ -0,0 +1,26 @@
+//  { dg-additional-options "-Wzero-as-null-pointer-constant -fsyntax-only" }
+
+#include <coroutine>
+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{};
+}