| 1 |
/* Verify that simple virtual calls are inlined even without early |
| 2 |
inlining, even when a typecast to an ancestor is involved along the |
| 3 |
way. */ |
| 4 |
/* { dg-do run { target { nonpic || pie_enabled } } } */ |
| 5 |
/* { dg-options "-O3 -fdump-ipa-inline -fno-early-inlining -fno-ipa-cp" } */ |
| 6 |
|
| 7 |
extern "C" void abort (void); |
| 8 |
|
| 9 |
class A |
| 10 |
{ |
| 11 |
public: |
| 12 |
int data; |
| 13 |
virtual int foo (int i); |
| 14 |
}; |
| 15 |
|
| 16 |
class B : public A |
| 17 |
{ |
| 18 |
public: |
| 19 |
virtual int foo (int i); |
| 20 |
}; |
| 21 |
|
| 22 |
class C : public A |
| 23 |
{ |
| 24 |
public: |
| 25 |
virtual int foo (int i); |
| 26 |
}; |
| 27 |
|
| 28 |
int A::foo (int i) |
| 29 |
{ |
| 30 |
return i + 1; |
| 31 |
} |
| 32 |
|
| 33 |
int B::foo (int i) |
| 34 |
{ |
| 35 |
return i + 2; |
| 36 |
} |
| 37 |
|
| 38 |
int C::foo (int i) |
| 39 |
{ |
| 40 |
return i + 3; |
| 41 |
} |
| 42 |
|
| 43 |
int __attribute__ ((noinline,noclone)) get_input(void) |
| 44 |
{ |
| 45 |
return 1; |
| 46 |
} |
| 47 |
|
| 48 |
static int middleman_1 (class A *obj, int i) |
| 49 |
{ |
| 50 |
return obj->foo (i); |
| 51 |
} |
| 52 |
|
| 53 |
static int middleman_2 (class B *obj, int i) |
| 54 |
{ |
| 55 |
return middleman_1 (obj, i); |
| 56 |
} |
| 57 |
|
| 58 |
int main (int argc, char *argv[]) |
| 59 |
{ |
| 60 |
class B b; |
| 61 |
int i; |
| 62 |
|
| 63 |
for (i = 0; i < get_input (); i++) |
| 64 |
if (middleman_2 (&b, get_input ()) != 3) |
| 65 |
abort (); |
| 66 |
return 0; |
| 67 |
} |
| 68 |
|
| 69 |
/* { dg-final { scan-ipa-dump "B::foo\[^\\n\]*inline copy in int main" "inline" } } */ |