1 // { dg-do run } 2 3 // Check that we can use multiple co_awaits 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 bar(int x,int y)15bar (int x, int y) 16 { 17 return x + y; 18 } 19 20 /* Function with a multiple awaits. */ 21 coro1 g()22g () 23 { 24 gX = bar (co_await 9, co_await 2); 25 co_return gX + 31; 26 } 27 main()28int main () 29 { 30 PRINT ("main: create coro1"); 31 struct coro1 g_coro = g (); 32 PRINT ("main: got coro1 - checking gX"); 33 if (gX != 1) 34 { 35 PRINTF ("main: gX is wrong : %d, should be 1\n", gX); 36 abort (); 37 } 38 if (g_coro.handle.done()) 39 { 40 PRINT ("main: we should not be 'done' [1]"); 41 abort (); 42 } 43 44 PRINT ("main: resuming [1] (initial suspend)"); 45 g_coro.handle.resume(); 46 47 PRINT ("main: resuming [2] (parm 1)"); 48 g_coro.handle.resume(); 49 PRINT ("main: resuming [2] (parm 2)"); 50 g_coro.handle.resume(); 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 puts ("main: done"); 72 return 0; 73 }