| 1 |
/* Verify that simple virtual calls are converted to direct calls by ipa-cp. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized" } */ |
| 4 |
|
| 5 |
extern "C" void abort (void); |
| 6 |
|
| 7 |
class A |
| 8 |
{ |
| 9 |
public: |
| 10 |
int data; |
| 11 |
virtual int foo (int i); |
| 12 |
}; |
| 13 |
|
| 14 |
class B : public A |
| 15 |
{ |
| 16 |
public: |
| 17 |
virtual int foo (int i); |
| 18 |
}; |
| 19 |
|
| 20 |
class C : public A |
| 21 |
{ |
| 22 |
public: |
| 23 |
virtual int foo (int i); |
| 24 |
}; |
| 25 |
|
| 26 |
int A::foo (int i) |
| 27 |
{ |
| 28 |
return i + 1; |
| 29 |
} |
| 30 |
|
| 31 |
int B::foo (int i) |
| 32 |
{ |
| 33 |
return i + 2; |
| 34 |
} |
| 35 |
|
| 36 |
int C::foo (int i) |
| 37 |
{ |
| 38 |
return i + 3; |
| 39 |
} |
| 40 |
|
| 41 |
static int middleman (class A *obj, int i) |
| 42 |
{ |
| 43 |
return obj->foo (i); |
| 44 |
} |
| 45 |
|
| 46 |
int __attribute__ ((noinline,noclone)) get_input(void) |
| 47 |
{ |
| 48 |
return 1; |
| 49 |
} |
| 50 |
|
| 51 |
int main (int argc, char *argv[]) |
| 52 |
{ |
| 53 |
class B b; |
| 54 |
if (middleman (&b, get_input ()) != 3) |
| 55 |
abort (); |
| 56 |
return 0; |
| 57 |
} |
| 58 |
|
| 59 |
/* { dg-final { scan-ipa-dump "Discovered a virtual call to a known target.*B::foo" "cp" } } */ |
| 60 |
/* { dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 0 "optimized"} } */ |