public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] coroutines: Fix ICE with an invalid await_suspend type [PR100673].
@ 2021-10-03 19:52 Iain Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain Sandoe @ 2021-10-03 19:52 UTC (permalink / raw)
  To: gcc-patches

From: John Eivind Helset <jehelset@gmail.com>

Hi,

The reported ICE occurs when an invalid (non-template) type is found
as the return for an await_suspend.

Fixed by amending build_co_await to ensure that await_suspend return-
type is a template-instantiation before checking to see if it is a
valid coroutine handle type.

Patch by John Eivind Helset, tested on x86_64, powerpc64le linux and
x86_64 darwin, pushed to master as trivial/obvious, thanks
Iain

Signed-off-by: John Eivind Helset <jehelset@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

	PR c++/100673

gcc/cp/ChangeLog:

	* coroutines.cc (build_co_await): Guard against NULL
	await_suspend types.

gcc/testsuite/ChangeLog:

	* g++.dg/coroutines/pr100673.C: New test.
---
 gcc/cp/coroutines.cc                       |  3 ++-
 gcc/testsuite/g++.dg/coroutines/pr100673.C | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/coroutines/pr100673.C

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index bff5b6343e5..1dd9abd1e1f 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1053,7 +1053,8 @@ build_co_await (location_t loc, tree a, suspend_point_kind suspend_kind)
   else if (same_type_p (susp_return_type, boolean_type_node))
     ok = true;
   else if (TREE_CODE (susp_return_type) == RECORD_TYPE
-	   && CLASS_TYPE_P (susp_return_type))
+	   && CLASS_TYPE_P (susp_return_type)
+	   && CLASSTYPE_TEMPLATE_INFO (susp_return_type))
     {
       tree tt = CLASSTYPE_TI_TEMPLATE (susp_return_type);
       if (tt == coro_handle_templ)
diff --git a/gcc/testsuite/g++.dg/coroutines/pr100673.C b/gcc/testsuite/g++.dg/coroutines/pr100673.C
new file mode 100644
index 00000000000..750ce66ae15
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr100673.C
@@ -0,0 +1,18 @@
+//  { dg-additional-options "-fsyntax-only -w" }
+
+// Diagnose bad coroutine awatiable type.
+
+#include<coroutine>
+
+struct coro{
+  struct not_a_template{};
+  using promise_type = coro;
+  static constexpr std::suspend_always initial_suspend()noexcept{ return {}; }
+  constexpr bool await_ready()noexcept{ return false; }
+  constexpr not_a_template await_suspend(std::coroutine_handle<>)noexcept{ return{}; }
+  constexpr void await_resume()noexcept{}
+  static coro body()
+  {
+    co_await coro{}; // { dg-error {'await_suspend' must return 'void', 'bool' or a coroutine handle} }
+  }
+};
-- 
2.24.3 (Apple Git-128)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-03 19:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-03 19:52 [pushed] coroutines: Fix ICE with an invalid await_suspend type [PR100673] Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).