| 1 |
/* Verify that IPA-CP can do devirtualization even if the virtual call |
| 2 |
comes from a method that has been early-inlined into a descendant. */ |
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-options "-O3 -fdump-ipa-cp -fno-ipa-vrp" } */ |
| 5 |
/* { dg-add-options bind_pic_locally } */ |
| 6 |
|
| 7 |
extern "C" void abort (void); |
| 8 |
|
| 9 |
class Distraction |
| 10 |
{ |
| 11 |
public: |
| 12 |
float f; |
| 13 |
double d; |
| 14 |
Distraction () |
| 15 |
{ |
| 16 |
f = 8.3; |
| 17 |
d = 10.2; |
| 18 |
} |
| 19 |
virtual float bar (float z); |
| 20 |
}; |
| 21 |
|
| 22 |
class A |
| 23 |
{ |
| 24 |
public: |
| 25 |
int data; |
| 26 |
virtual int foo (int i); |
| 27 |
int middleman_1 (int i); |
| 28 |
}; |
| 29 |
|
| 30 |
|
| 31 |
class B : public Distraction, public A |
| 32 |
{ |
| 33 |
public: |
| 34 |
virtual int foo (int i); |
| 35 |
int middleman_2 (int i); |
| 36 |
__attribute__ ((noinline)) B(); |
| 37 |
}; |
| 38 |
|
| 39 |
float Distraction::bar (float z) |
| 40 |
{ |
| 41 |
f += z; |
| 42 |
return f/2; |
| 43 |
} |
| 44 |
|
| 45 |
int A::foo (int i) |
| 46 |
{ |
| 47 |
return i + 1; |
| 48 |
} |
| 49 |
|
| 50 |
int B::foo (int i) |
| 51 |
{ |
| 52 |
return i + 2; |
| 53 |
} |
| 54 |
|
| 55 |
int __attribute__ ((noinline,noclone)) get_input(void) |
| 56 |
{ |
| 57 |
return 1; |
| 58 |
} |
| 59 |
|
| 60 |
int inline __attribute__ ((always_inline)) |
| 61 |
A::middleman_1 (int i) |
| 62 |
{ |
| 63 |
return this->foo (i); |
| 64 |
} |
| 65 |
|
| 66 |
int __attribute__ ((noinline)) |
| 67 |
B::middleman_2 (int i) |
| 68 |
{ |
| 69 |
return this->middleman_1 (i); |
| 70 |
} |
| 71 |
|
| 72 |
B::B () |
| 73 |
{ |
| 74 |
} |
| 75 |
|
| 76 |
int main (int argc, char *argv[]) |
| 77 |
{ |
| 78 |
class B b; |
| 79 |
int i; |
| 80 |
|
| 81 |
for (i = 0; i < get_input(); i++) |
| 82 |
if (b.middleman_2 (get_input ()) != 3) |
| 83 |
abort (); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
/* { dg-final { scan-ipa-dump "Discovered a virtual call to a known target.*B::foo" "cp" } } */ |