Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c

raw
1 /* { dg-do compile { target tail_call } } */
2 /* Allow nested functions. */
3 /* { dg-options "-Wno-pedantic" } */
4
5 struct box { char field[64]; int i; };
6
7 struct box __attribute__((noinline,noclone))
8 returns_struct (int i)
9 {
10 struct box b;
11 b.i = i * i;
12 return b;
13 }
14
15 int __attribute__((noinline,noclone))
16 test_1 (int i)
17 {
18 return returns_struct (i * 5).i; /* { dg-error "cannot tail-call: " } */
19 }
20
21 int __attribute__((noinline,noclone))
22 test_2_callee (int i, struct box b)
23 {
24 if (b.field[0])
25 return 5;
26 return i * i;
27 }
28
29 int __attribute__((noinline,noclone))
30 test_2_caller (int i)
31 {
32 struct box b;
33 return test_2_callee (i + 1, b); /* { dg-error "cannot tail-call: " } */
34 }
35
36 extern void setjmp (void);
37 void
38 test_3 (void)
39 {
40 setjmp (); /* { dg-error "cannot tail-call: " } */
41 }
42
43 void
44 test_4 (void)
45 {
46 void nested (void)
47 {
48 }
49 nested (); /* { dg-error "cannot tail-call: " } */
50 }
51
52 typedef void (fn_ptr_t) (void);
53 volatile fn_ptr_t fn_ptr;
54
55 void
56 test_5 (void)
57 {
58 fn_ptr ();
59 }