| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining" } */ |
| 3 |
struct A { |
| 4 |
virtual int foo () {return 1;} |
| 5 |
void wrapfoo () {foo();} |
| 6 |
A() {wrapfoo();} |
| 7 |
}; |
| 8 |
inline void* operator new(__SIZE_TYPE__ s, void* buf) throw() { |
| 9 |
return buf; |
| 10 |
} |
| 11 |
struct B:A {virtual int foo () {return 2;}}; |
| 12 |
|
| 13 |
void dostuff(struct A *); |
| 14 |
|
| 15 |
static void |
| 16 |
test2 (struct A *a) |
| 17 |
{ |
| 18 |
dostuff (a); |
| 19 |
if (a->foo ()!= 2) |
| 20 |
__builtin_abort (); |
| 21 |
} |
| 22 |
|
| 23 |
static void |
| 24 |
test (struct A *a) |
| 25 |
{ |
| 26 |
dostuff (a); |
| 27 |
static_cast<B*>(a)->~B(); |
| 28 |
new(a) B(); |
| 29 |
test2(a); |
| 30 |
} |
| 31 |
|
| 32 |
int main() |
| 33 |
{ |
| 34 |
struct B a; |
| 35 |
dostuff (&a); |
| 36 |
test (&a); |
| 37 |
} |
| 38 |
|
| 39 |
/* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */ |
| 40 |
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 2 "inline" { target { ! implicit_constexpr } } } }*/ |
| 41 |
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline" } } */ |