1 /* { dg-do run { target trampolines } } */
2 /* { dg-options "-O2" } */
3 /* { dg-additional-sources "tailcall-7.c" } */
4 
5 struct s { int x; };
6 extern struct s global;
7 
8 void g1 (void);
9 void g2 (void);
10 void g3 (struct s *);
11 struct s g4 (struct s);
12 struct s g5 (void);
13 struct s g6 (void);
14 struct s g7 (void);
15 struct s g8 (struct s *);
16 int g9 (struct s);
17 int g10 (int);
18 
19 struct s last;
20 struct s tmp;
21 
22 struct s
f(int i)23 f (int i)
24 {
25   struct s ret;
26   ret.x = i + 100;
27   last = ret;
28   return ret;
29 }
30 
31 void
callit(void (* fn)(void))32 callit (void (*fn) (void))
33 {
34   fn ();
35 }
36 
37 int
test(int last_val,int global_val,int tmp_val)38 test (int last_val, int global_val, int tmp_val)
39 {
40   return last.x == last_val && global.x == global_val && tmp.x == tmp_val;
41 }
42 
43 int
main(void)44 main (void)
45 {
46   global.x = 200;
47   tmp.x = 300;
48   g1 ();
49   if (!test (101, 200, 300))
50     __builtin_abort ();
51   g2 ();
52   if (!test (102, 102, 300))
53     __builtin_abort ();
54   g3 (&tmp);
55   if (!test (103, 102, 103))
56     __builtin_abort ();
57   if (g4 (tmp).x != 104 || !test (104, 102, 103))
58     __builtin_abort ();
59   if (g5 ().x != 105 || !test (105, 102, 103))
60     __builtin_abort ();
61   if (g6 ().x != 106 || !test (106, 102, 103))
62     __builtin_abort ();
63   if (g7 ().x != 107 || !test (107, 107, 103))
64     __builtin_abort ();
65   if (g8 (&tmp).x != 108 || !test (108, 107, 108))
66     __builtin_abort ();
67   if (g9 (tmp) != 9 || !test (109, 107, 108))
68     __builtin_abort ();
69   if (g10 (10) != 10 || !test (110, 107, 108))
70     __builtin_abort ();
71   return 0;
72 }
73