public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9510] coroutines : Remove throwing_cleanup marks from the ramp [PR95822].
@ 2021-03-22 22:03 Iain D Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2021-03-22 22:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9f13c7ad960a0f2e150dd2f668a8d155b76389db

commit r10-9510-g9f13c7ad960a0f2e150dd2f668a8d155b76389db
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Tue Feb 16 09:07:32 2021 +0000

    coroutines : Remove throwing_cleanup marks from the ramp [PR95822].
    
    The FE contains a mechanism for cleaning up return expressions if a
    function throws during the execution of cleanups prior to the return.
    
    If the original function has a return value with a non-trivial DTOR
    and the body contains a var with a DTOR that might throw, the function
    decl is marked "throwing_cleanup".
    
    However, we do not [in the coroutine ramp function, which is
    synthesised], use any body var types with DTORs that might throw.
    
    The original body [which will then contain the type with the throwing
    DTOR] is transformed into the actor function which only contains void
    returns, and is also wrapped in a try-catch block.
    
    So (a) the 'throwing_cleanup' is no longer correct for the ramp and
       (b) we do not need to transfer it to the actor which only contains
           void returns.
    
    gcc/cp/ChangeLog:
    
            PR c++/95822
            * coroutines.cc (morph_fn_to_coro): Unconditionally remove any
            set throwing_cleanup marker.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/95822
            * g++.dg/coroutines/pr95822.C: New test.
    
    (cherry picked from commit 7005a50d0121954031a223ea5a6c57aaa7e3efd3)

Diff:
---
 gcc/cp/coroutines.cc                      | 11 +++++++++++
 gcc/testsuite/g++.dg/coroutines/pr95822.C | 29 +++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index a6f11536c91..f107e6fbb87 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4047,6 +4047,17 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
       TREE_OPERAND (body_start, 0) = push_stmt_list ();
     }
 
+  /* If the original function has a return value with a non-trivial DTOR
+     and the body contains a var with a DTOR that might throw, the decl is
+     marked "throwing_cleanup".
+     We do not [in the ramp, which is synthesised here], use any body var
+     types with DTORs that might throw.
+     The original body is transformed into the actor function which only
+     contains void returns, and is also wrapped in a try-catch block.
+     So (a) the 'throwing_cleanup' is not correct for the ramp and (b) we do
+     not need to transfer it to the actor which only contains void returns.  */
+  cp_function_chain->throwing_cleanup = false;
+
   /* Create the coro frame type, as far as it can be known at this stage.
      1. Types we already know.  */
 
diff --git a/gcc/testsuite/g++.dg/coroutines/pr95822.C b/gcc/testsuite/g++.dg/coroutines/pr95822.C
new file mode 100644
index 00000000000..f6284aa417e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr95822.C
@@ -0,0 +1,29 @@
+#include <coroutine>
+
+struct task {
+  struct promise_type {
+    auto initial_suspend() noexcept { return std::suspend_always{}; }
+    auto final_suspend() noexcept { return std::suspend_always{}; }
+    void return_void() {}
+    task get_return_object() { return task{}; }
+    void unhandled_exception() noexcept {}
+  };
+
+  ~task() noexcept {}
+
+  bool await_ready() const noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
+struct Error {
+   Error() { };
+  ~Error() noexcept(false) {}
+};
+
+task g();
+
+task f() {
+  Error error;
+  co_await g();
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-22 22:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 22:03 [gcc r10-9510] coroutines : Remove throwing_cleanup marks from the ramp [PR95822] Iain D Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).