summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2020-05-07 19:48:31 +0100
committerIain Sandoe <iain@sandoe.co.uk>2020-05-07 21:06:43 +0100
commitc7100843831147a034fe37d231c54ac53ceace45 (patch)
treecfd8d1b58df219af0386ac27e2e3dfabd17b7226 /gcc/cp
parentf1d9467714a6dfcb8791037e502f84df927d0084 (diff)
coroutines: Improve error recovery [PR94817, PR94829].
When we have completely missing key information (e.g. the coroutine_traits) or a partially transformed function body, we need to try and balance returning useful information about failures with the possibility that some part of the diagnostics machinery or following code will not be able to handle the state. The PRs (and revised testcase) point to cases where that processing has failed. This revises the process to avoid special handling for the ramp, and falls back on the same code used for regular function fails. There are test-cases (in addition to the ones for the PRs) that now cover all early exit points [where the transforms are considered to have failed in a manner that does not allow compilation to continue]. gcc/cp/ChangeLog: 2020-05-07 Iain Sandoe <iain@sandoe.co.uk> PR c++/94817 PR c++/94829 * coroutines.cc (morph_fn_to_coro): Set unformed outline functions to error_mark_node. For early error returns suppress warnings about missing ramp return values. Fix reinstatement of the function body on pre-existing initial error. * decl.c (finish_function): Use the normal error path for fails in the ramp function, do not try to compile the helpers if the transform fails. gcc/testsuite/ChangeLog: 2020-05-07 Iain Sandoe <iain@sandoe.co.uk> PR c++/94817 PR c++/94829 * g++.dg/coroutines/coro-missing-final-suspend.C: New test. * g++.dg/coroutines/coro-missing-initial-suspend.C: New test. * g++.dg/coroutines/coro-missing-promise-yield.C: Check for continuation of compilation. * g++.dg/coroutines/coro-missing-promise.C: Likewise. * g++.dg/coroutines/coro-missing-ret-value.C: Likewise * g++.dg/coroutines/coro-missing-ret-void.C: Likewise * g++.dg/coroutines/coro-missing-ueh-3.C: Likewise * g++.dg/coroutines/pr94817.C: New test. * g++.dg/coroutines/pr94829.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/coroutines.cc31
-rw-r--r--gcc/cp/decl.c20
3 files changed, 47 insertions, 16 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 031741e2264..0c19a6fe47c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2020-05-07 Iain Sandoe <iain@sandoe.co.uk>
+
+ PR c++/94817
+ PR c++/94829
+ * coroutines.cc (morph_fn_to_coro): Set unformed outline
+ functions to error_mark_node. For early error returns suppress
+ warnings about missing ramp return values. Fix reinstatement
+ of the function body on pre-existing initial error.
+ * decl.c (finish_function): Use the normal error path for fails
+ in the ramp function, do not try to compile the helpers if the
+ transform fails.
+
2020-05-07 Marek Polacek <polacek@redhat.com>
PR c++/94590 - Detect long double -> double narrowing.
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index fc319a58cc2..8f0f2d5960d 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -3540,14 +3540,21 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
{
gcc_checking_assert (orig && TREE_CODE (orig) == FUNCTION_DECL);
+ *resumer = error_mark_node;
+ *destroyer = error_mark_node;
if (!coro_function_valid_p (orig))
- return false;
+ {
+ /* For early errors, we do not want a diagnostic about the missing
+ ramp return value, since the user cannot fix this - a 'return' is
+ not allowed in a coroutine. */
+ TREE_NO_WARNING (orig) = true;
+ return false;
+ }
/* We can't validly get here with an empty statement list, since there's no
way for the FE to decide it's a coroutine in the absence of any code. */
tree fnbody = pop_stmt_list (DECL_SAVED_TREE (orig));
- if (fnbody == NULL_TREE)
- return false;
+ gcc_checking_assert (fnbody != NULL_TREE);
/* We don't have the locus of the opening brace - it's filled in later (and
there doesn't really seem to be any easy way to get at it).
@@ -3561,7 +3568,9 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
if (body_start == NULL_TREE || body_start == error_mark_node)
{
DECL_SAVED_TREE (orig) = push_stmt_list ();
- append_to_statement_list (DECL_SAVED_TREE (orig), &fnbody);
+ append_to_statement_list (fnbody, &DECL_SAVED_TREE (orig));
+ /* Suppress warnings about the missing return value. */
+ TREE_NO_WARNING (orig) = true;
return false;
}
@@ -3630,13 +3639,21 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
the coroutine promise. */
tree initial_await = build_init_or_final_await (fn_start, false);
if (initial_await == error_mark_node)
- return false;
+ {
+ /* Suppress warnings about the missing return value. */
+ TREE_NO_WARNING (orig) = true;
+ return false;
+ }
/* The type of the frame var for this is the type of its temp proxy. */
tree initial_suspend_type = TREE_TYPE (TREE_OPERAND (initial_await, 1));
tree final_await = build_init_or_final_await (fn_start, true);
if (final_await == error_mark_node)
- return false;
+ {
+ /* Suppress warnings about the missing return value. */
+ TREE_NO_WARNING (orig) = true;
+ return false;
+ }
/* The type of the frame var for this is the type of its temp proxy. */
tree final_suspend_type = TREE_TYPE (TREE_OPERAND (final_await, 1));
@@ -4219,6 +4236,8 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
{
BIND_EXPR_BODY (ramp_bind) = pop_stmt_list (ramp_body);
DECL_SAVED_TREE (orig) = newbody;
+ /* Suppress warnings about the missing return value. */
+ TREE_NO_WARNING (orig) = true;
return false;
}
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index cc12e005154..73a06a60786 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -16886,6 +16886,7 @@ finish_function (bool inline_p)
bool coro_p = flag_coroutines
&& !processing_template_decl
&& DECL_COROUTINE_P (fndecl);
+ bool coro_emit_helpers = false;
/* When we get some parse errors, we can end up without a
current_function_decl, so cope. */
@@ -16914,18 +16915,16 @@ finish_function (bool inline_p)
if (coro_p)
{
- if (!morph_fn_to_coro (fndecl, &resumer, &destroyer))
- {
- DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
- poplevel (1, 0, 1);
- DECL_SAVED_TREE (fndecl) = error_mark_node;
- return fndecl;
- }
+ /* Only try to emit the coroutine outlined helper functions if the
+ transforms succeeded. Otherwise, treat errors in the same way as
+ a regular function. */
+ coro_emit_helpers = morph_fn_to_coro (fndecl, &resumer, &destroyer);
/* We should handle coroutine IFNs in middle end lowering. */
cfun->coroutine_component = true;
- if (use_eh_spec_block (fndecl))
+ /* Do not try to process the ramp's EH unless outlining succeeded. */
+ if (coro_emit_helpers && use_eh_spec_block (fndecl))
finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
(TREE_TYPE (fndecl)),
current_eh_spec_block);
@@ -17174,8 +17173,9 @@ finish_function (bool inline_p)
&& !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
cp_genericize (fndecl);
- /* Emit the resumer and destroyer functions now. */
- if (coro_p)
+ /* Emit the resumer and destroyer functions now, providing that we have
+ not encountered some fatal error. */
+ if (coro_emit_helpers)
{
emit_coro_helper (resumer);
emit_coro_helper (destroyer);