OSDN Git Service

PR c/10175
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / sibcall-4.c
1 /* Simple check that sibling calls are performed from a
2    void non-leaf-function taking no arguments calling a function which
3    is about the same as itself.
4
5    Copyright (C) 2002 Free Software Foundation Inc.
6    Contributed by Hans-Peter Nilsson  <hp@bitrange.com>  */
7
8 /* { dg-do run { xfail arc-*-* avr-*-* c4x-*-* cris-*-* h8300-*-* i370-*-* i960-*-* ip2k-*-* m32r-*-* m68hc1?-*-* m681?-*-* m680*-*-* m68k-*-* mcore-*-* mips*-*-* mn10?00-*-* ns32k-*-* s390*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
9 /* { dg-options "-O2 -foptimize-sibling-calls" } */
10
11 /* The option -foptimize-sibling-calls is the default, but serves as
12    marker.  This test is xfailed on targets without sibcall patterns
13    (except targets where the test does not work due to the return address
14    not saved on the regular stack).  */
15
16 static void recurser_void1 (void);
17 static void recurser_void2 (void);
18 extern void track (void);
19
20 int n = 0;
21 int main ()
22 {
23   recurser_void1 ();
24   exit (0);
25 }
26
27 /* The functions should get the same stack-frame, and best way to make it
28    reasonably sure is to make them have the same contents (regarding the
29    n tests).  */
30
31 static void
32 recurser_void1 (void)
33 {
34   if (n == 0 || n == 7 || n == 8)
35     track ();
36
37   if (n == 10)
38     return;
39   n++;
40   recurser_void2 ();
41 }
42
43 static void
44 recurser_void2 (void)
45 {
46   if (n == 0 || n == 7 || n == 8)
47     track ();
48
49   if (n == 10)
50     return;
51   n++;
52   recurser_void1 ();
53 }
54
55 void *trackpoint;
56
57 void
58 track ()
59 {
60   char stackpos[1];
61
62   if (n == 0)
63     trackpoint = stackpos;
64   else if ((n != 7 && n != 8) || trackpoint != stackpos)
65     abort ();
66 }