| 1 |
/* { dg-options "-O2 -fdump-ipa-devirt-details -fdump-tree-fre1-details" } */ |
| 2 |
struct A {virtual int t(void) {return 1;}}; |
| 3 |
struct B:A {B(); virtual int t(void) {return 2;}}; |
| 4 |
void test2(struct A *); |
| 5 |
int |
| 6 |
m(struct B *b) |
| 7 |
{ |
| 8 |
struct A *a = new (B); |
| 9 |
a->t(); // This call should be devirtualized by |
| 10 |
// FRE because we know type from ctor call |
| 11 |
((struct B *)a)->B::t(); // Make devirt possible |
| 12 |
// C++ FE won't produce inline body without this |
| 13 |
test2(a); |
| 14 |
return a->t(); // This call should be devirtualized speculatively because |
| 15 |
// test2 may change the type of A by placement new. |
| 16 |
// C++ standard is bit imprecise about this. |
| 17 |
} |
| 18 |
/* { dg-final { scan-tree-dump "converting indirect call to function virtual int B::t" "fre1" { target { ! implicit_constexpr } } } } */ |
| 19 |
/* { dg-final { scan-ipa-dump "to virtual int B::t" "devirt" { target { ! implicit_constexpr } } } } */ |
| 20 |
/* { dg-final { scan-ipa-dump "1 speculatively devirtualized" "devirt" } } */ |