| 1 |
/* Origin: trampoline-1.c Waldek Hebisch <[email protected]> */ |
| 2 |
/* Ported to test -Wtrampolines Magnus Granberg <[email protected]> */ |
| 3 |
|
| 4 |
/* { dg-do compile } */ |
| 5 |
/* { dg-require-effective-target trampolines } */ |
| 6 |
/* { dg-options "-O2 -Wtrampolines" } */ |
| 7 |
|
| 8 |
/* macOS 11 and above use heap-based trampolines, which do not emit a warning. */ |
| 9 |
/* { dg-skip-if "" { *-*-darwin2* } } */ |
| 10 |
|
| 11 |
/* This used to fail on various versions of Solaris 2 because the |
| 12 |
trampoline couldn't be made executable. */ |
| 13 |
|
| 14 |
extern void abort(void); |
| 15 |
extern double fabs(double); |
| 16 |
|
| 17 |
void foo (void) |
| 18 |
{ |
| 19 |
const int correct[1100] = {1, 0, -2, 0, 1, 0, 1, -1, -10, -30, -67}; |
| 20 |
int i; |
| 21 |
|
| 22 |
double x1 (void) {return 1; } |
| 23 |
double x2 (void) {return -1;} |
| 24 |
double x3 (void) {return -1;} |
| 25 |
double x4 (void) {return 1; } |
| 26 |
double x5 (void) {return 0; } |
| 27 |
|
| 28 |
typedef double pfun(void); |
| 29 |
|
| 30 |
double a (int k, pfun x1, pfun x2, pfun x3, pfun x4, pfun x5) |
| 31 |
{ |
| 32 |
double b (void) /* { dg-warning "trampoline generated for nested function 'b'" "standard descriptors" { xfail { { ia64-*-* *-*-aix* } || { powerpc*-*-* && lp64 } } } } */ |
| 33 |
{ |
| 34 |
k = k - 1; |
| 35 |
return a (k, b, x1, x2, x3, x4 ); |
| 36 |
} |
| 37 |
|
| 38 |
if (k <= 0) |
| 39 |
return x4 () + x5 (); |
| 40 |
else |
| 41 |
return b (); |
| 42 |
} |
| 43 |
|
| 44 |
for (i=0; i<=10; i++) |
| 45 |
{ |
| 46 |
if (fabs(a( i, x1, x2, x3, x4, x5 ) - correct [i]) > 0.1) |
| 47 |
abort(); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
int main (void) |
| 52 |
{ |
| 53 |
foo (); |
| 54 |
|
| 55 |
return 0; |
| 56 |
} |