coroutines: Fix ICE on invalid (PR93458).
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 3 Feb 2020 19:15:31 +0000 (19:15 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Mon, 3 Feb 2020 19:48:23 +0000 (19:48 +0000)
commitd60c25fa02044181196768fa8b63980e0f535c38
tree769bfa056316fcdfb207877504778d435dbe30a9
parent833f1e66e3a8efdbb941a44ac9e74101d771e0d5
coroutines: Fix ICE on invalid (PR93458).

Since coroutine-ness is discovered lazily, we encounter the diagnostics
during each keyword parse.  We were not handling the case where a user code
failed to include fundamental information (e.g. the traits) in a graceful
manner.

Once we've emitted an error for this level of fail, then we suppress
additional copies (otherwise the same thing will be reported for every
coroutine keyword seen).

gcc/cp/ChangeLog:

2020-02-03  Iain Sandoe  <iain@sandoe.co.uk>

* coroutines.cc (struct coroutine_info): Add a bool flag to note
that we emitted an error for a bad function return type.
(get_coroutine_info): Tolerate an unset info table in case of
missing traits.
(find_coro_traits_template_decl): In case of error or if we didn't
find a type template, note we emitted the error and suppress
duplicates.
(find_coro_handle_template_decl): Likewise.
(instantiate_coro_traits): Only check for error_mark_node in the
return from lookup_qualified_name.
(coro_promise_type_found_p): Reorder initialization so that we check
for the traits and their usability before allocation of the info
table.  Check for a suitable return type and emit a diagnostic for
here instead of relying on the lookup machinery.  This allows the
error to have a better location, and means we can suppress multiple
copies.
(coro_function_valid_p): Re-check for a valid promise (and thus the
traits) before proceeding.  Tolerate missing info as a fatal error.

gcc/testsuite/ChangeLog:

2020-02-03  Iain Sandoe  <iain@sandoe.co.uk>

* g++.dg/coroutines/pr93458-1-missing-traits.C: New test.
* g++.dg/coroutines/pr93458-2-bad-traits.C: New test.
* g++.dg/coroutines/pr93458-3-missing-handle.C: New test.
* g++.dg/coroutines/pr93458-4-bad-coro-handle.C: New test.
* g++.dg/coroutines/pr93458-5-bad-coro-type.C: New test.
gcc/cp/ChangeLog
gcc/cp/coroutines.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/coroutines/pr93458-1-missing-traits.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr93458-2-bad-traits.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr93458-3-missing-handle.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr93458-4-bad-coro-handle.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr93458-5-bad-coro-type.C [new file with mode: 0644]