| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining -fdump-tree-optimized" } */ |
| 3 |
struct A { |
| 4 |
virtual int foo () {return 1;} |
| 5 |
int bar () {return foo();} |
| 6 |
int barbar (); |
| 7 |
}; |
| 8 |
namespace { |
| 9 |
struct B:A {virtual int foo () {return 2;} |
| 10 |
int barbar () {return bar();}}; |
| 11 |
} |
| 12 |
|
| 13 |
int |
| 14 |
A::barbar() |
| 15 |
{ |
| 16 |
return static_cast<B*>(this)->barbar(); |
| 17 |
} |
| 18 |
|
| 19 |
int main() |
| 20 |
{ |
| 21 |
struct B b; |
| 22 |
struct A *a = &b; |
| 23 |
return a->barbar (); |
| 24 |
} |
| 25 |
|
| 26 |
/* Inlining everything into main makes type clear from type of variable b. |
| 27 |
However devirtualization is also possible for offline copy of A::barbar. Invoking |
| 28 |
B's barbar makes it clear the type is at least B and B is an anonymous |
| 29 |
namespace type and therefore we know it has no derivations. */ |
| 30 |
/* { dg-final { scan-ipa-dump "First type is base of second" "inline" } } */ |
| 31 |
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 2 "inline" } } */ |
| 32 |
|
| 33 |
/* Verify that speculation is optimized by late optimizers. */ |
| 34 |
/* { dg-final { scan-tree-dump-times "return 2" 3 "optimized" } } */ |
| 35 |
/* { dg-final { scan-tree-dump-not "OBJ_TYPE_REF" "optimized" } } */ |
| 36 |
|