| 1 |
/* Verify that virtual calls are folded even early inlining puts them into one |
| 2 |
function with the definition. */ |
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-options "-O2 -fdump-tree-einline-optimized" } */ |
| 5 |
|
| 6 |
extern "C" void abort (void); |
| 7 |
|
| 8 |
class A |
| 9 |
{ |
| 10 |
public: |
| 11 |
int data; |
| 12 |
virtual int foo (int i); |
| 13 |
}; |
| 14 |
|
| 15 |
|
| 16 |
class B : public A |
| 17 |
{ |
| 18 |
public: |
| 19 |
__attribute__ ((noinline)) B(); |
| 20 |
virtual int foo (int i); |
| 21 |
}; |
| 22 |
|
| 23 |
int __attribute__ ((noinline)) A::foo (int i) |
| 24 |
{ |
| 25 |
return i + 1; |
| 26 |
} |
| 27 |
|
| 28 |
int __attribute__ ((noinline)) B::foo (int i) |
| 29 |
{ |
| 30 |
return i + 2; |
| 31 |
} |
| 32 |
|
| 33 |
int __attribute__ ((noinline,noclone)) get_input(void) |
| 34 |
{ |
| 35 |
return 1; |
| 36 |
} |
| 37 |
|
| 38 |
__attribute__ ((noinline)) B::B() |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
static inline int middleman_1 (class A *obj, int i) |
| 43 |
{ |
| 44 |
return obj->foo (i); |
| 45 |
} |
| 46 |
|
| 47 |
static inline int middleman_2 (class B *obj, int i) |
| 48 |
{ |
| 49 |
return middleman_1 (obj, i); |
| 50 |
} |
| 51 |
|
| 52 |
int main (int argc, char *argv[]) |
| 53 |
{ |
| 54 |
class B b; |
| 55 |
|
| 56 |
if (middleman_2 (&b, get_input ()) != 3) |
| 57 |
abort (); |
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
/* middleman_2 gets early inlined and the virtual call should get turned to |
| 62 |
a direct call. */ |
| 63 |
/* { dg-final { scan-tree-dump "Inlining int middleman_1" "einline" { target { ! implicit_constexpr } } } } */ |
| 64 |
/* { dg-final { scan-tree-dump "Inlining int middleman_2" "einline" { target { ! implicit_constexpr } } } } */ |
| 65 |
/* { dg-final { scan-tree-dump "B::foo \\(" "einline" } } */ |
| 66 |
/* { dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 2 "einline" } } */ |