Commit 03cb20e5 by Jim Wilson Committed by Kito Cheng

Update 2 C++ coroutine testcases from upstream.

Fixes use-after-free bugs exposed by new glibc version.
parent c3911e64
...@@ -5,20 +5,23 @@ ...@@ -5,20 +5,23 @@
#include "../coro.h" #include "../coro.h"
int g_promise = -1;
template<typename R, typename HandleRef, typename ...T> template<typename R, typename HandleRef, typename ...T>
struct std::coroutine_traits<R, HandleRef, T...> { struct std::coroutine_traits<R, HandleRef, T...> {
struct promise_type { struct promise_type {
promise_type (HandleRef h, T ...args) promise_type (HandleRef h, T ...args)
{ h = std::coroutine_handle<promise_type>::from_promise (*this); { h = std::coroutine_handle<promise_type>::from_promise (*this);
PRINT ("Created Promise"); PRINT ("Created Promise");
g_promise = 1;
} }
~promise_type () { PRINT ("Destroyed Promise"); g_promise = 0;}
void get_return_object() {} void get_return_object() {}
auto initial_suspend() { auto initial_suspend() {
return std::suspend_always{}; return std::suspend_always{};
} }
auto final_suspend() { return std::suspend_never{}; } auto final_suspend() noexcept { return std::suspend_never{}; }
void return_void() {} void return_void() {}
void unhandled_exception() {} void unhandled_exception() {}
...@@ -45,10 +48,11 @@ int main () ...@@ -45,10 +48,11 @@ int main ()
// initial suspend. // initial suspend.
h.resume (); h.resume ();
if (!h.done()) // The coro should have self-destructed.
if (g_promise)
{ {
PRINT ("main: apparently wasn't done..."); PRINT ("main: apparently we did not complete...");
abort (); abort ();
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
struct pt_b struct pt_b
{ {
std::suspend_always initial_suspend() const noexcept { return {}; } std::suspend_always initial_suspend() const noexcept { return {}; }
std::suspend_never final_suspend() const noexcept { return {}; } std::suspend_always final_suspend() const noexcept { return {}; }
constexpr void return_void () noexcept {}; constexpr void return_void () noexcept {};
constexpr void unhandled_exception() const noexcept {} constexpr void unhandled_exception() const noexcept {}
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment