https://gcc.gnu.org/g:e83c4bfc338fad0c87b2debb37ccfe98d148c7ac

commit r16-1507-ge83c4bfc338fad0c87b2debb37ccfe98d148c7ac
Author: Iain Sandoe <i...@sandoe.co.uk>
Date:   Sat Jun 7 17:01:15 2025 +0100

    c++, coroutines: Ensure that the resumer is marked as can_throw.
    
    We must flag that the resumer might throw (since the wrapping of the
    original function body unconditionally adds a try-catch/rethrow). We
    also add code that might throw - even when the original function body
    would not.
    
    TODO: We could improve code-gen by recognising cases where the combined
    body + initial await expressions cannot throw and omitting the unneeded
    try/catch/rethrow wrapper.
    
    gcc/cp/ChangeLog:
    
            * coroutines.cc (build_actor_fn): Set can_throw.
    
    Signed-off-by: Iain Sandoe <i...@sandoe.co.uk>

Diff:
---
 gcc/cp/coroutines.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 97eee6e8ea4d..bd61785a4ef5 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -2406,6 +2406,11 @@ build_actor_fn (location_t loc, tree coro_frame_type, 
tree actor, tree fnbody,
   bool spf = start_preparsed_function (actor, NULL_TREE, SF_PRE_PARSED);
   gcc_checking_assert (spf);
   gcc_checking_assert (cfun && current_function_decl && TREE_STATIC (actor));
+  if (flag_exceptions)
+    /* We, unconditionally, add a try/catch and rethrow.
+       TODO: Determine if the combination of initial suspend and the original
+       body cannot throw, and elide these additions.  */
+    cp_function_chain->can_throw = true;
   tree stmt = begin_function_body ();
 
   tree actor_bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);

Reply via email to