Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/call-01-multiple-co-aw.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Check that we can use multiple co_awaits as a call parm.
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #define USE_AWAIT_TRANSFORM
10 #include "../coro1-ret-int-yield-int.h"
11
12 int gX = 1;
13
14 __attribute__((__noinline__))
15 static int
16 bar (int x, int y)
17 {
18 return x + y;
19 }
20
21 /* Function with a multiple awaits. */
22 coro1
23 g ()
24 {
25 gX = bar (co_await 9, co_await 2);
26 co_return gX + 31;
27 }
28
29 int main ()
30 {
31 PRINT ("main: create coro1");
32 struct coro1 g_coro = g ();
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 if (g_coro.handle.done())
40 {
41 PRINT ("main: we should not be 'done' [1]");
42 abort ();
43 }
44
45 PRINT ("main: resuming [1] (initial suspend)");
46 g_coro.handle.resume();
47
48 PRINT ("main: resuming [2] (parm 1)");
49 g_coro.handle.resume();
50 PRINT ("main: resuming [2] (parm 2)");
51 g_coro.handle.resume();
52 if (gX != 11)
53 {
54 PRINTF ("main: gX is wrong : %d, should be 11\n", gX);
55 abort ();
56 }
57
58 /* we should now have returned with the co_return 11 + 31) */
59 if (!g_coro.handle.done())
60 {
61 PRINT ("main: we should be 'done'");
62 abort ();
63 }
64
65 int y = g_coro.handle.promise().get_value();
66 if (y != 42)
67 {
68 PRINTF ("main: y is wrong : %d, should be 42\n", y);
69 abort ();
70 }
71
72 PRINT ("main: done");
73 return 0;
74 }