1 // { dg-do run } 2 3 // Check that we can use co_await as a call parm. 4 5 #include "../coro.h" 6 7 // boiler-plate for tests of codegen 8 #define USE_AWAIT_TRANSFORM 9 #include "../coro1-ret-int-yield-int.h" 10 11 int gX = 1; 12 13 __attribute__((__noinline__)) 14 static int foo(int x)15foo (int x) 16 { 17 return x + 2; 18 } 19 20 /* Function with a single await. */ 21 coro1 f()22f () 23 { 24 gX = foo (co_await 9); 25 co_return gX + 31; 26 } 27 main()28int main () 29 { 30 PRINT ("main: create coro1"); 31 struct coro1 f_coro = f (); 32 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 40 if (f_coro.handle.done()) 41 { 42 PRINT ("main: we should not be 'done' [1]"); 43 abort (); 44 } 45 46 PRINT ("main: resuming [1] (initial suspend)"); 47 f_coro.handle.resume(); 48 PRINT ("main: resuming [2] (await 9 parm)"); 49 f_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 (!f_coro.handle.done()) 59 { 60 PRINT ("main: we should be 'done'"); 61 abort (); 62 } 63 64 int y = f_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 puts ("main: done"); 72 return 0; 73 }