1 //  { dg-do run }
2 
3 #include "../coro.h"
4 
5 // boiler-plate for tests of codegen
6 #define USE_AWAIT_TRANSFORM
7 #include "../coro1-ret-int-yield-int.h"
8 
9 /* Valued with an await_transform.  */
10 int gX = 1;
f()11 coro1 f ()
12 {
13   gX = co_await 11 + co_await 15;
14   co_return gX + 31;
15 }
16 
main()17 int main ()
18 {
19   PRINT ("main: create coro1");
20   struct coro1 f_coro = f ();
21   PRINT ("main: got coro1 - checking gX");
22   if (gX != 1)
23     {
24       PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
25       abort ();
26     }
27   if (f_coro.handle.done())
28     {
29       PRINT ("main: we should not be 'done' [1]");
30       abort ();
31     }
32   PRINT ("main: resuming [1] (initial suspend)");
33   f_coro.handle.resume();
34   PRINT ("main: resuming [2] one side of add");
35   f_coro.handle.resume();
36   PRINT ("main: resuming [3] other side of add");
37   f_coro.handle.resume();
38   if (gX != 26)
39     {
40       PRINTF ("main: gX is wrong : %d, should be 26\n", gX);
41       abort ();
42     }
43   /* we should now have returned with the co_return (57) */
44   if (!f_coro.handle.done())
45     {
46       PRINT ("main: we should be 'done' ");
47       abort ();
48     }
49   int y = f_coro.handle.promise().get_value();
50   if (y != 57)
51     {
52       PRINTF ("main: y is wrong : %d, should be 57\n", y);
53       abort ();
54     }
55   puts ("main: done");
56   return 0;
57 }
58