| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Check that we can use co_await as a call parm. |
| 5 |
|
| 6 |
#include "../coro.h" |
| 7 |
|
| 8 |
// boiler-plate for tests of codegen |
| 9 |
#define USE_AWAIT_TRANSFORM |
| 10 |
#include "../coro1-ret-int-yield-int.h" |
| 11 |
|
| 12 |
int gX = 1; |
| 13 |
|
| 14 |
__attribute__((__noinline__)) |
| 15 |
static int |
| 16 |
foo (int x) |
| 17 |
{ |
| 18 |
return x + 2; |
| 19 |
} |
| 20 |
|
| 21 |
/* Function with a single await. */ |
| 22 |
coro1 |
| 23 |
f () |
| 24 |
{ |
| 25 |
gX = foo (co_await 9); |
| 26 |
co_return gX + 31; |
| 27 |
} |
| 28 |
|
| 29 |
int main () |
| 30 |
{ |
| 31 |
PRINT ("main: create coro1"); |
| 32 |
struct coro1 f_coro = f (); |
| 33 |
|
| 34 |
PRINT ("main: got coro1 - checking gX"); |
| 35 |
if (gX != 1) |
| 36 |
{ |
| 37 |
PRINTF ("main: gX is wrong : %d, should be 1\n", gX); |
| 38 |
abort (); |
| 39 |
} |
| 40 |
|
| 41 |
if (f_coro.handle.done()) |
| 42 |
{ |
| 43 |
PRINT ("main: we should not be 'done' [1]"); |
| 44 |
abort (); |
| 45 |
} |
| 46 |
|
| 47 |
PRINT ("main: resuming [1] (initial suspend)"); |
| 48 |
f_coro.handle.resume(); |
| 49 |
PRINT ("main: resuming [2] (await 9 parm)"); |
| 50 |
f_coro.handle.resume(); |
| 51 |
|
| 52 |
if (gX != 11) |
| 53 |
{ |
| 54 |
PRINTF ("main: gX is wrong : %d, should be 11\n", gX); |
| 55 |
abort (); |
| 56 |
} |
| 57 |
|
| 58 |
/* we should now have returned with the co_return 11 + 31) */ |
| 59 |
if (!f_coro.handle.done()) |
| 60 |
{ |
| 61 |
PRINT ("main: we should be 'done'"); |
| 62 |
abort (); |
| 63 |
} |
| 64 |
|
| 65 |
int y = f_coro.handle.promise().get_value(); |
| 66 |
if (y != 42) |
| 67 |
{ |
| 68 |
PRINTF ("main: y is wrong : %d, should be 42\n", y); |
| 69 |
abort (); |
| 70 |
} |
| 71 |
|
| 72 |
PRINT ("main: done"); |
| 73 |
return 0; |
| 74 |
} |