| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Check foo (compiler temp, co_await). |
| 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 |
bar (int x, int y) |
| 17 |
{ |
| 18 |
return x + y; |
| 19 |
} |
| 20 |
|
| 21 |
/* Function with a compiler temporary and a co_await. */ |
| 22 |
coro1 |
| 23 |
g () |
| 24 |
{ |
| 25 |
gX = bar (gX + 8, co_await 2); |
| 26 |
co_return gX + 31; |
| 27 |
} |
| 28 |
|
| 29 |
int main () |
| 30 |
{ |
| 31 |
PRINT ("main: create coro1"); |
| 32 |
struct coro1 g_coro = g (); |
| 33 |
PRINT ("main: got coro1 - checking gX"); |
| 34 |
if (gX != 1) |
| 35 |
{ |
| 36 |
PRINTF ("main: gX is wrong : %d, should be 1\n", gX); |
| 37 |
abort (); |
| 38 |
} |
| 39 |
if (g_coro.handle.done()) |
| 40 |
{ |
| 41 |
PRINT ("main: we should not be 'done' [1]"); |
| 42 |
abort (); |
| 43 |
} |
| 44 |
|
| 45 |
PRINT ("main: resuming [1] (initial suspend)"); |
| 46 |
g_coro.handle.resume(); |
| 47 |
|
| 48 |
PRINT ("main: resuming [2] (parm 1)"); |
| 49 |
g_coro.handle.resume(); |
| 50 |
|
| 51 |
if (gX != 11) |
| 52 |
{ |
| 53 |
PRINTF ("main: gX is wrong : %d, should be 11\n", gX); |
| 54 |
abort (); |
| 55 |
} |
| 56 |
|
| 57 |
/* we should now have returned with the co_return 11 + 31) */ |
| 58 |
if (!g_coro.handle.done()) |
| 59 |
{ |
| 60 |
PRINT ("main: we should be 'done'"); |
| 61 |
abort (); |
| 62 |
} |
| 63 |
|
| 64 |
int y = g_coro.handle.promise().get_value(); |
| 65 |
if (y != 42) |
| 66 |
{ |
| 67 |
PRINTF ("main: y is wrong : %d, should be 42\n", y); |
| 68 |
abort (); |
| 69 |
} |
| 70 |
|
| 71 |
PRINT ("main: done"); |
| 72 |
return 0; |
| 73 |
} |