Debian Codegraph @

gcc/testsuite/c-c++-common/musttail30.c

raw
1 /* { dg-do compile { target { musttail && { c || c++11 } } } } */
2 /* { dg-options "-Wextra" } */
3
4 int foo (int, void *);
5 int bar (int, int *);
6 struct S { int a, b, c; };
7 struct T { int d; struct S e; };
8
9 int
10 baz (int x, void *y)
11 {
12 [[gnu::musttail]] return bar (2, &x); /* { dg-warning "address of parameter 'x' passed to 'musttail' call argument" } */
13 }
14
15 int
16 qux (int x, void *y)
17 {
18 __label__ lab;
19 lab:;
20 if (*(int *) y == 1)
21 [[gnu::musttail]] return foo (1, &&lab); /* { dg-warning "address of label passed to 'musttail' call argument" } */
22 if (x == 1)
23 [[gnu::musttail]] return foo (3, 0);
24 else if (x == 2)
25 {
26 {
27 int a = 42;
28 bar (4, &a);
29 }
30 [[gnu::musttail]] return bar (5, 0);
31 }
32 else if (x == 3)
33 {
34 int a = 42;
35 bar (4, &a);
36 [[gnu::musttail]] return bar (6, 0); /* { dg-warning "address of automatic variable 'a' can escape to 'musttail' call" } */
37 }
38 else if (x == 4)
39 {
40 int a = 42;
41 [[gnu::musttail]] return bar (7, &a); /* { dg-warning "address of automatic variable 'a' passed to 'musttail' call argument" } */
42 }
43 else if (x == 5)
44 {
45 struct T b;
46 [[gnu::musttail]] return bar (8, &b.e.b); /* { dg-warning "address of automatic variable 'b' passed to 'musttail' call argument" } */
47 }
48 else if (x == 6)
49 {
50 struct T b;
51 bar (9, &b.e.a);
52 [[gnu::musttail]] return bar (10, 0); /* { dg-warning "address of automatic variable 'b' can escape to 'musttail' call" } */
53 }
54 else if (x == 7)
55 {
56 {
57 struct T b;
58 bar (9, &b.e.a);
59 }
60 [[gnu::musttail]] return bar (11, 0);
61 }
62 else if (x == 8)
63 {
64 {
65 int a = 42;
66 bar (4, &a);
67 }
68 [[gnu::musttail]] return foo (12, 0);
69 }
70 else if (x == 9)
71 {
72 int a = 42;
73 bar (4, &a);
74 [[gnu::musttail]] return foo (13, 0); /* { dg-warning "address of automatic variable 'a' can escape to 'musttail' call" } */
75 }
76 else if (x == 10)
77 {
78 int a = 42;
79 [[gnu::musttail]] return foo (14, &a); /* { dg-warning "address of automatic variable 'a' passed to 'musttail' call argument" } */
80 }
81 else if (x == 11)
82 {
83 struct T b;
84 [[gnu::musttail]] return foo (15, &b.e.b); /* { dg-warning "address of automatic variable 'b' passed to 'musttail' call argument" } */
85 }
86 else if (x == 12)
87 {
88 struct T b;
89 bar (9, &b.e.a);
90 [[gnu::musttail]] return foo (16, 0); /* { dg-warning "address of automatic variable 'b' can escape to 'musttail' call" } */
91 }
92 else if (x == 13)
93 {
94 {
95 struct T b;
96 bar (9, &b.e.a);
97 }
98 [[gnu::musttail]] return foo (17, 0);
99 }
100 return 0;
101 }
102
103 int
104 corge (int x, void *y)
105 {
106 if (*(int *) y == 1)
107 bar (18, &x);
108 [[gnu::musttail]] return bar (2, 0); /* { dg-warning "address of parameter 'x' can escape to 'musttail' call" } */
109 }