1 /* Simple check that sibling calls are performed from a
2 void non-leaf-function taking one int argument calling itself.
3
4 Copyright (C) 2002 Free Software Foundation Inc.
5 Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
6
7 /* { dg-do run } */
8 /* { dg-options "-O2 -foptimize-sibling-calls" } */
9
10 /* See note in recurser_void() as to why we disable threading. */
11 /* { dg-additional-options "-fdisable-tree-thread1" } */
12
13 /* The option -foptimize-sibling-calls is the default, but serves as
14 marker. Self-recursion tail calls are optimized for all targets,
15 regardless of presence of sibcall patterns. */
16
17 extern void abort (void);
18 extern void exit (int);
19
20 extern void recurser_void (int);
21 extern void track (int);
22
23 int main ()
24 {
25 recurser_void (0);
26 exit (0);
27 }
28
29 void
30 recurser_void (int n)
31 {
32 /* In some architectures like ppc64*, jump threading may thread
33 paths such that there are two calls into track(), one for
34 track(0) and one for track(7). The track(7) call can be
35 transformed into a jump instead of a call, which means that
36 different calls into track() may end up with a different
37 &stackpos. This is the reason we disable jump threading for this
38 test. */
39 if (n == 0 || n == 7)
40 track (n);
41
42 if (n == 10)
43 return;
44
45 recurser_void (n + 1);
46 }
47
48 void *trackpoint;
49
50 void __attribute__ ((noipa))
51 track (int n)
52 {
53 char stackpos[1];
54
55 if (n == 0)
56 trackpoint = stackpos;
57 else if (n != 7 || trackpoint != stackpos)
58 abort ();
59 }