Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-await-04-control-flow.C

raw
1 // { dg-do run }
2 // { dg-additional-options "-Wno-unused-label" }
3 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
4
5 // Check correct operation of await transform.
6
7 #include "../coro.h"
8
9 // boiler-plate for tests of codegen
10 #define USE_AWAIT_TRANSFORM
11 #include "../coro1-ret-int-yield-int.h"
12
13 /* Valued with an await_transform. */
14 int gX = 1;
15 int y = 30;
16
17 coro1
18 f ()
19 {
20 if (gX < 12) {
21 L1:
22 gX += y;
23 gX += co_await 11;
24 } else
25 L2:
26 gX += co_await 12;
27
28 co_return gX;
29 }
30
31 int main ()
32 {
33 PRINT ("main: create coro1");
34 struct coro1 f_coro = f ();
35 PRINT ("main: got coro1 - checking gX");
36 if (gX != 1)
37 {
38 PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
39 abort ();
40 }
41 PRINT ("main: gX OK -- looping");
42 do {
43 PRINTF ("main: gX : %d \n", gX);
44 f_coro.handle.resume();
45 } while (!f_coro.handle.done());
46 int y = f_coro.handle.promise().get_value();
47 if (y != 42)
48 {
49 PRINTF ("main: y is wrong : %d, should be 42\n", y);
50 abort ();
51 }
52 PRINT ("main: done");
53 return 0;
54 }