diff mbox series

[pushed] c++, coroutines: Check for malformed functions before splitting.

Message ID 20240821082828.62860-1-iain@sandoe.co.uk
State New
Headers show
Series [pushed] c++, coroutines: Check for malformed functions before splitting. | expand

Commit Message

Iain Sandoe Aug. 21, 2024, 8:28 a.m. UTC
tested on x86_64-darwin, powerpc64-linux and against cppcoro and
folly coroutines tests, pushed to trunk as obvious, thanks,
Iain

--- 8< ---

This performs the same basic check that is done by finish_function
to catch cases where the function is so badly malformed that we
do not have a consistent binding level.

gcc/cp/ChangeLog:

	* coroutines.cc (split_coroutine_body_from_ramp): Check
	that the binding level is as expected before attempting
	to outline the function body.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
---
 gcc/cp/coroutines.cc | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Jason Merrill Aug. 21, 2024, 8:28 p.m. UTC | #1
On 8/21/24 4:28 AM, Iain Sandoe wrote:
> tested on x86_64-darwin, powerpc64-linux and against cppcoro and
> folly coroutines tests, pushed to trunk as obvious, thanks,
> Iain
> 
> --- 8< ---
> 
> This performs the same basic check that is done by finish_function
> to catch cases where the function is so badly malformed that we
> do not have a consistent binding level.
> 
> gcc/cp/ChangeLog:
> 
> 	* coroutines.cc (split_coroutine_body_from_ramp): Check
> 	that the binding level is as expected before attempting
> 	to outline the function body.
> 
> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
> ---
>   gcc/cp/coroutines.cc | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
> index f7791cbfb9a..7af2a188561 100644
> --- a/gcc/cp/coroutines.cc
> +++ b/gcc/cp/coroutines.cc
> @@ -4553,10 +4553,16 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig,
>   static tree
>   split_coroutine_body_from_ramp (tree fndecl)
>   {
> -  tree body;
> +  /* Sanity-check and punt if we have a nonsense tree because of earlier
> +     parse errors, perhaps.  */
> +  if (!current_binding_level
> +      || current_binding_level->kind != sk_function_parms)
> +    return NULL_TREE;

Maybe assert seen_error in this case?

Jason
diff mbox series

Patch

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index f7791cbfb9a..7af2a188561 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4553,10 +4553,16 @@  coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig,
 static tree
 split_coroutine_body_from_ramp (tree fndecl)
 {
-  tree body;
+  /* Sanity-check and punt if we have a nonsense tree because of earlier
+     parse errors, perhaps.  */
+  if (!current_binding_level
+      || current_binding_level->kind != sk_function_parms)
+    return NULL_TREE;
+
   /* Once we've tied off the original user-authored body in fn_body.
      Start the replacement synthesized ramp body.  */
 
+  tree body;
   if (use_eh_spec_block (fndecl))
     {
       body = pop_stmt_list (TREE_OPERAND (current_eh_spec_block, 0));