[pushed] coroutines: Look through NOPs for awaiter variables [PR 99575].
Iain Sandoe
iains.gcc@gmail.com
Sun Oct 3 19:45:27 GMT 2021
Hi,
There was a missing STRIP_NOPS which meant that, in some cases,
an awaiter variable could be hidden by a view-convert-expr.
tested on x86_64, powerpc64le linux and x86_86 darwin.
pushed to master as trivial/obvious.
thanks,
Iain
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR c++/99575
gcc/cp/ChangeLog:
* coroutines.cc (build_co_await): Strip NOPs from
candidate awaiter expressions before testing to see
if they need a temporary.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/pr99575.C: New test.
---
gcc/cp/coroutines.cc | 1 +
gcc/testsuite/g++.dg/coroutines/pr99575.C | 35 +++++++++++++++++++++++
2 files changed, 36 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/coroutines/pr99575.C
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 2f45575bd92..876a14606f8 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1008,6 +1008,7 @@ build_co_await (location_t loc, tree a, suspend_point_kind suspend_kind)
}
/* Only build a temporary if we need it. */
+ STRIP_NOPS (e_proxy);
if (TREE_CODE (e_proxy) == PARM_DECL
|| (VAR_P (e_proxy) && !is_local_temp (e_proxy)))
{
diff --git a/gcc/testsuite/g++.dg/coroutines/pr99575.C b/gcc/testsuite/g++.dg/coroutines/pr99575.C
new file mode 100644
index 00000000000..d5f86c1812e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr99575.C
@@ -0,0 +1,35 @@
+
+#include <coroutine>
+
+class Task {
+ public:
+ struct promise_type {
+ Task get_return_object() { return Task{}; }
+ std::suspend_always initial_suspend() { return {}; }
+ std::suspend_always final_suspend() noexcept { return {}; }
+ void unhandled_exception() {}
+ void return_void() {}
+ };
+
+ bool await_ready() const { return false; }
+ void await_suspend(std::coroutine_handle<void> continuation) {}
+ void await_resume() {}
+};
+
+class NonMoveableTask {
+ public:
+ NonMoveableTask() = default;
+ NonMoveableTask(const NonMoveableTask&) = delete;
+ NonMoveableTask(NonMoveableTask&&) = delete;
+
+ NonMoveableTask& operator=(const NonMoveableTask&) = delete;
+ NonMoveableTask& operator=(NonMoveableTask&& other) = delete;
+
+ bool await_ready() const { return false; }
+ void await_suspend(std::coroutine_handle<void>) {}
+ void await_resume() {}
+};
+
+Task Foo(NonMoveableTask* task) { co_await* task; }
+
+int main() {}
--
2.24.3 (Apple Git-128)
More information about the Gcc-patches
mailing list