diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2020-05-03 14:20:13 +0100 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2020-05-08 20:45:31 +0100 |
commit | 234681eadf2c51d7b78270188d64601b7267330d (patch) | |
tree | ce8493990ed194e757ae76291a4e965858b30cac /gcc/testsuite | |
parent | 810a2bd8784d745e1b446fb13ce56bee3be16b81 (diff) |
coroutines: Update TREE_SIDE_EFFECTS on inserted bind exprs.
There are several places where we insert bind expressions while
making the coroutine AST transforms. These should be marked as
having side-effects where relevant, which had been omitted. This
leads to at least one failure in the cppcoros test suite, where a loop
body is dropped in gimplification because it is not marked.
gcc/cp/ChangeLog:
2020-05-08 Iain Sandoe <iain@sandoe.co.uk>
PR c++/95003
* coroutines.cc (build_actor_fn): Ensure that bind scopes
are marked as having side-effects where necessary.
(replace_statement_captures): Likewise.
(morph_fn_to_coro): Likewise.
gcc/testsuite/ChangeLog:
2020-05-08 Iain Sandoe <iain@sandoe.co.uk>
PR c++/95003
* g++.dg/coroutines/torture/pr95003.C: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/coroutines/torture/pr95003.C | 50 |
2 files changed, 55 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2381a1c80f9..69c3cac3d71 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-05-08 Iain Sandoe <iain@sandoe.co.uk> + + PR c++/95003 + * g++.dg/coroutines/torture/pr95003.C: New test. + 2020-05-08 Nathan Sidwell <nathan@acm.org> * gcc.dg/cpp/counter-[23].c: Move to c-c+_-common/cpp. diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr95003.C b/gcc/testsuite/g++.dg/coroutines/torture/pr95003.C new file mode 100644 index 00000000000..eda785827ec --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/pr95003.C @@ -0,0 +1,50 @@ +// { dg-do run } + +#include "../coro.h" +#include "../coro1-ret-int-yield-int.h" + +// This tests that, when we insert bind scopes to contain variables that +// have been promoted from compiler temporaries to extend their lifetimes +// to a containing full expression, the inserted bind scopes have their +// tree-side-effects set. + +struct Awaitable { + int v; + Awaitable (int _v) : v(_v) {} + bool await_ready() { return false; } + void await_suspend(std::coroutine_handle<coro1::promise_type>) {} + int await_resume() { return v; } + auto operator co_await() { return *this; } +}; + +coro1 +my_coro +(int x) +{ + int sum = 0; + for (unsigned i = 0; i < 100; ++i) { + sum += co_await Awaitable{x+1}; + } + co_return sum; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 f_coro = my_coro (0); + + PRINT ("main: OK -- looping"); + + do { + f_coro.handle.resume(); + } while (!f_coro.handle.done()); + + int y = f_coro.handle.promise().get_value(); + if (y != 100) + { + PRINTF ("main: y is wrong : %d, should be 100\n", y); + abort (); + } + puts ("main: done"); + return 0; +} |