aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorBin Cheng <bin.cheng@linux.alibaba.com>2020-01-30 12:10:36 +0800
committerBin Cheng <bin.cheng@linux.alibaba.com>2020-01-30 12:35:46 +0800
commit3b35b3d4cc26816d1c6342b880f303b577ecbb84 (patch)
treed738593ac0d2e49e22d4143489b689e037e5ea67 /gcc
parent66af5a226acd0edfbafcbcac76ed268cee0612ed (diff)
downloadgcc-3b35b3d4cc26816d1c6342b880f303b577ecbb84.zip
gcc-3b35b3d4cc26816d1c6342b880f303b577ecbb84.tar.gz
gcc-3b35b3d4cc26816d1c6342b880f303b577ecbb84.tar.bz2
Handle CO_AWAIT_EXPR in conversion in co_await_expander.
Function co_await_expander expands CO_AWAIT_EXPR and inserts expanded code before result of co_await is used, however, it doesn't cover the type conversion case and leads to gimplify ICE. This patch fixes it. gcc/cp * coroutines.cc (co_await_expander): Handle type conversion case. gcc/testsuite * g++.dg/coroutines/co-await-syntax-09-convert.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/coroutines.cc8
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/coroutines/co-await-syntax-09-convert.C23
4 files changed, 40 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b307583..3356524 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-30 Bin Cheng <bin.cheng@linux.alibaba.com>
+
+ * coroutines.cc (co_await_expander): Handle type conversion case.
+
2020-01-29 Jason Merrill <jason@redhat.com>
PR c++/90333
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index e8a6a40..7deb6f6 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1357,6 +1357,9 @@ co_await_expander (tree *stmt, int * /*do_subtree*/, void *d)
&buried_stmt, NULL))
saved_co_await = r;
}
+ else if ((stmt_code == CONVERT_EXPR || stmt_code == NOP_EXPR)
+ && TREE_CODE (TREE_OPERAND (stripped_stmt, 0)) == CO_AWAIT_EXPR)
+ saved_co_await = TREE_OPERAND (stripped_stmt, 0);
if (!saved_co_await)
return NULL_TREE;
@@ -1514,6 +1517,11 @@ co_await_expander (tree *stmt, int * /*do_subtree*/, void *d)
default: /* not likely to work .. but... */
append_to_statement_list (resume_call, &stmt_list);
break;
+ case CONVERT_EXPR:
+ case NOP_EXPR:
+ TREE_OPERAND (stripped_stmt, 0) = resume_call;
+ append_to_statement_list (saved_statement, &stmt_list);
+ break;
case INIT_EXPR:
case MODIFY_EXPR:
case CALL_EXPR:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 57d6120..30e804b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-30 Bin Cheng <bin.cheng@linux.alibaba.com>
+
+ * g++.dg/coroutines/co-await-syntax-09-convert.C: New test.
+
2020-01-30 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/92706
@@ -946,7 +950,7 @@
* gcc.target/i386/pr93319-1a.c: Don't include <stdio.h>.
(test1): Replace printf with __builtin_printf.
-2020-01-21 Bin Cheng <bin.linux@linux.alibaba.com>
+2020-01-21 Bin Cheng <bin.cheng@linux.alibaba.com>
* g++.dg/coroutines/co-await-void_type.C: New test.
diff --git a/gcc/testsuite/g++.dg/coroutines/co-await-syntax-09-convert.C b/gcc/testsuite/g++.dg/coroutines/co-await-syntax-09-convert.C
new file mode 100644
index 0000000..dde0bab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/co-await-syntax-09-convert.C
@@ -0,0 +1,23 @@
+// { dg-additional-options "-std=c++17 -w" }
+
+#include "coro.h"
+
+class mycoro {
+public:
+ class promise_type {
+ public:
+ std::suspend_always initial_suspend() const noexcept { return {}; }
+ std::suspend_always final_suspend() const noexcept { return {}; }
+ void unhandled_exception() noexcept { }
+ mycoro get_return_object() { return mycoro{}; }
+ };
+};
+
+class await {
+public:
+ bool await_ready() const noexcept { return false; }
+ bool await_suspend(std::coroutine_handle<>) noexcept {return true;}
+ mycoro await_resume() { return mycoro{}; }
+};
+
+mycoro foo(mycoro source) { (void) co_await await{}; }