Debian Codegraph @

gcc/testsuite/g++.dg/ipa/imm-devirt-2.C

raw
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" } */
5
6 extern "C" void abort (void);
7
8 class Distraction
9 {
10 public:
11 float f;
12 double d;
13 Distraction ()
14 {
15 f = 8.3;
16 d = 10.2;
17 }
18 virtual float bar (float z);
19 };
20
21 class A
22 {
23 public:
24 int data;
25 virtual int foo (int i);
26 };
27
28 class B : public A
29 {
30 public:
31 int data_2;
32 virtual int foo (int i);
33 virtual int baz (int i);
34 };
35
36
37 class C : public Distraction, public B
38 {
39 public:
40 __attribute__ ((noinline)) C();
41 virtual int foo (int i);
42 };
43
44 float __attribute__ ((noinline)) Distraction::bar (float z)
45 {
46 f += z;
47 return f/2;
48 }
49
50 int __attribute__ ((noinline)) A::foo (int i)
51 {
52 return i + 1;
53 }
54
55 int __attribute__ ((noinline)) B::foo (int i)
56 {
57 return i + 2;
58 }
59
60 int __attribute__ ((noinline)) B::baz (int i)
61 {
62 return i * 15;
63 }
64
65 int __attribute__ ((noinline)) C::foo (int i)
66 {
67 return i + 3;
68 }
69
70 int __attribute__ ((noinline,noclone)) get_input(void)
71 {
72 return 1;
73 }
74
75 static inline int middleman (class A *obj, int i)
76 {
77 return obj->foo (i);
78 }
79
80 __attribute__ ((noinline)) C::C()
81 {
82 }
83
84 int main (int argc, char *argv[])
85 {
86 class C c;
87
88 if (middleman (&c, get_input ()) != 4)
89 abort ();
90
91 return 0;
92 }
93
94 /* We fold into thunk of C. Eventually we should inline the thunk. */
95 /* { dg-final { scan-tree-dump "C::_ZThn\[0-9\]+_N1C3fooEi \\(" "einline" } } */