| 1 |
/* Simple check that sibling calls are performed from a |
| 2 |
void non-leaf-function taking one int argument 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 <[email protected]> */ |
| 7 |
|
| 8 |
/* { dg-do run { xfail { { amdgcn*-*-* cris-*-* csky-*-* h8300-*-* hppa*64*-*-* m32r-*-* mcore-*-* mn10300-*-* msp430*-*-* nds32*-*-* nvptx-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa*-*-* } || { arm*-*-* && { ! arm32 } } } } } */ |
| 9 |
/* -mlongcall disables sibcall patterns. */ |
| 10 |
/* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */ |
| 11 |
/* -msave-restore disables sibcall patterns. */ |
| 12 |
/* { dg-skip-if "" { riscv*-*-* } { "-msave-restore" } { "" } } */ |
| 13 |
/* { dg-options "-O2 -foptimize-sibling-calls" } */ |
| 14 |
|
| 15 |
/* The option -foptimize-sibling-calls is the default, but serves as |
| 16 |
marker. This test is xfailed on targets without sibcall patterns |
| 17 |
(except targets where the test does not work due to the return address |
| 18 |
not saved on the regular stack). */ |
| 19 |
|
| 20 |
extern void abort (void); |
| 21 |
extern void exit (int); |
| 22 |
|
| 23 |
/* Sibcalls are not supported in MIPS16 mode, which has direct calls but |
| 24 |
not direct jumps. */ |
| 25 |
#ifdef __mips |
| 26 |
#define ATTR __attribute__((nomips16)) |
| 27 |
#else |
| 28 |
#define ATTR |
| 29 |
#endif |
| 30 |
|
| 31 |
static ATTR void recurser_void1 (int); |
| 32 |
static ATTR void recurser_void2 (int); |
| 33 |
extern void track (int); |
| 34 |
static volatile int v; |
| 35 |
|
| 36 |
int main () |
| 37 |
{ |
| 38 |
recurser_void1 (0); |
| 39 |
if (v != 5) |
| 40 |
abort (); |
| 41 |
exit (0); |
| 42 |
} |
| 43 |
|
| 44 |
/* The functions should get the same stack-frame, and best way to make it |
| 45 |
reasonably sure is to make them have the same contents (regarding the |
| 46 |
n tests). */ |
| 47 |
|
| 48 |
static void __attribute__((noipa)) ATTR |
| 49 |
recurser_void1 (int n) |
| 50 |
{ |
| 51 |
if (n == 0 || n == 7 || n == 8) |
| 52 |
track (n); |
| 53 |
|
| 54 |
if (n == 10) |
| 55 |
return; |
| 56 |
|
| 57 |
recurser_void2 (n + 1); |
| 58 |
} |
| 59 |
|
| 60 |
static void __attribute__((noipa)) ATTR |
| 61 |
recurser_void2 (int n) |
| 62 |
{ |
| 63 |
if (n == 0 || n == 7 || n == 8) |
| 64 |
track (n); |
| 65 |
|
| 66 |
if (n == 10) |
| 67 |
return; |
| 68 |
|
| 69 |
v++; |
| 70 |
recurser_void1 (n + 1); |
| 71 |
} |
| 72 |
|
| 73 |
void *trackpoint; |
| 74 |
|
| 75 |
void __attribute__ ((noipa)) |
| 76 |
track (int n) |
| 77 |
{ |
| 78 |
char stackpos[1]; |
| 79 |
|
| 80 |
if (n == 0) |
| 81 |
trackpoint = stackpos; |
| 82 |
else if ((n != 7 && n != 8) || trackpoint != stackpos) |
| 83 |
abort (); |
| 84 |
} |