1 // { dg-do run } 2 3 // Check correct operation of await transform. 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 /* Valued with an await_transform. */ 12 int gX = 1; 13 int y = 30; 14 15 coro1 f()16f () 17 { 18 if (gX < 12) { 19 L1: 20 gX += y; 21 gX += co_await 11; 22 } else 23 L2: 24 gX += co_await 12; 25 26 co_return gX; 27 } 28 main()29int main () 30 { 31 PRINT ("main: create coro1"); 32 struct coro1 f_coro = f (); 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 PRINT ("main: gX OK -- looping"); 40 do { 41 PRINTF ("main: gX : %d \n", gX); 42 f_coro.handle.resume(); 43 } while (!f_coro.handle.done()); 44 int y = f_coro.handle.promise().get_value(); 45 if (y != 42) 46 { 47 PRINTF ("main: y is wrong : %d, should be 42\n", y); 48 abort (); 49 } 50 puts ("main: done"); 51 return 0; 52 } 53