| 1 |
/* { dg-do compile { target { struct_musttail } } } */ |
| 2 |
/* { dg-require-effective-target external_musttail } */ |
| 3 |
/* A lot of architectures will not build this due to PR115606 and PR115607 */ |
| 4 |
/* { dg-options "-std=gnu++11" } */ |
| 5 |
/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ |
| 6 |
|
| 7 |
class Foo { |
| 8 |
public: |
| 9 |
int a, b; |
| 10 |
Foo(int a, int b) : a(a), b(b) {} |
| 11 |
}; |
| 12 |
|
| 13 |
Foo __attribute__((noinline,noclone,noipa)) |
| 14 |
callee (int i) |
| 15 |
{ |
| 16 |
return Foo(i, i+1); |
| 17 |
} |
| 18 |
|
| 19 |
Foo __attribute__((noinline,noclone,noipa)) |
| 20 |
caller (int i) |
| 21 |
{ |
| 22 |
__attribute__((__musttail__)) return callee (i + 1); |
| 23 |
} |
| 24 |
|
| 25 |
template<typename T> |
| 26 |
T __attribute__((noinline,noclone,noipa)) foo (T i) |
| 27 |
{ |
| 28 |
return i + 1; |
| 29 |
} |
| 30 |
|
| 31 |
int |
| 32 |
caller2 (int k) |
| 33 |
{ |
| 34 |
__attribute__((__musttail__)) return foo<int>(1); |
| 35 |
} |
| 36 |
|
| 37 |
template<typename T> |
| 38 |
T caller3 (T v) |
| 39 |
{ |
| 40 |
__attribute__((__musttail__)) return foo<T>(v); |
| 41 |
} |
| 42 |
|
| 43 |
int call3(int i) |
| 44 |
{ |
| 45 |
__attribute__((__musttail__)) return caller3<int>(i + 1); |
| 46 |
} |
| 47 |
|
| 48 |
struct Bar { |
| 49 |
int a; |
| 50 |
Bar(int a) : a(a) {} |
| 51 |
Bar operator+(Bar o) { return Bar(a + o.a); } |
| 52 |
}; |
| 53 |
|
| 54 |
#if __OPTIMIZE__ >= 1 |
| 55 |
Bar |
| 56 |
caller4 (Bar k) |
| 57 |
{ |
| 58 |
__attribute__((__musttail__)) return caller3<Bar>(Bar(99)); |
| 59 |
} |
| 60 |
#endif |