Tested on x86_64-darwin, x86_64-linux, OK for trunk? thanks Iain --- 8< ---
At present, we only update the suspend index when we actually are at the stage that the coroutine is considered suspended. This is on the basis that it is UB to resume or destroy a coroutines that is not suspended (and therefore we never need to access this value otherwise). However, it is possible that someone could set a debug breakpoint on the resume which can be reached without suspending if await_ready() returns true. In that case, the debugger would read an incorrect suspend index. Fixed by moving the update to just before the test for ready. gcc/cp/ChangeLog: * coroutines.cc (expand_one_await_expression): Update the suspend point index before checking if the coroutine is ready. Signed-off-by: Iain Sandoe <i...@sandoe.co.uk> --- gcc/cp/coroutines.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 3148559d208..b36730d793c 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1964,6 +1964,11 @@ expand_one_await_expression (tree *expr, tree *await_expr, void *d) /* Use the await_ready() call to test if we need to suspend. */ tree ready_cond = TREE_VEC_ELT (awaiter_calls, 0); /* await_ready(). */ + /* We are about to pass this suspend point. */ + tree susp_idx = build_int_cst (short_unsigned_type_node, data->index); + tree r = cp_build_init_expr (data->resume_idx, susp_idx); + finish_expr_stmt (r); + /* Convert to bool, if necessary. */ if (TREE_CODE (TREE_TYPE (ready_cond)) != BOOLEAN_TYPE) ready_cond = cp_convert (boolean_type_node, ready_cond, @@ -1974,10 +1979,6 @@ expand_one_await_expression (tree *expr, tree *await_expr, void *d) ready_cond = invert_truthvalue_loc (loc, ready_cond); finish_if_stmt_cond (ready_cond, susp_if); - tree susp_idx = build_int_cst (short_unsigned_type_node, data->index); - tree r = cp_build_init_expr (data->resume_idx, susp_idx); - finish_expr_stmt (r); - /* Find out what we have to do with the awaiter's suspend method. [expr.await] (5.1) If the result of await-ready is false, the coroutine is considered -- 2.39.2 (Apple Git-143)