coroutines, testsuite: Fix co-ret-17-void-ret-coro.C.
This was a bad testcase, found with fsanitize=address; the final suspend is 'suspend never' which flows off the end of the coroutine destroying the promise and the frame. At that point access via the handle is an error. Fixed by checking that the promise is destroyed via a global var. gcc/testsuite/ChangeLog: * g++.dg/coroutines/torture/co-ret-17-void-ret-coro.C: Check for promise destruction via a global variable.
This commit is contained in:
parent
c8462662da
commit
f6615c2133
@ -5,14 +5,17 @@
|
|||||||
|
|
||||||
#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() {
|
||||||
@ -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 ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user