Debian Codegraph @

gcc/testsuite/g++.dg/ipa/ivinline-7.C

raw
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 and that ancestor is not the first one with virtual functions. */
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 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 };
28
29
30 class B : public Distraction, public A
31 {
32 public:
33 virtual int foo (int i);
34 };
35
36 float Distraction::bar (float z)
37 {
38 f += z;
39 return f/2;
40 }
41
42 int A::foo (int i)
43 {
44 return i + 1;
45 }
46
47 int B::foo (int i)
48 {
49 return i + 2;
50 }
51
52 int __attribute__ ((noinline,noclone)) get_input(void)
53 {
54 return 1;
55 }
56
57 static int middleman_1 (class A *obj, int i)
58 {
59 return obj->foo (i);
60 }
61
62 static int middleman_2 (class B *obj, int i)
63 {
64 return middleman_1 (obj, i);
65 }
66
67 int main (int argc, char *argv[])
68 {
69 class B b;
70 int i;
71
72 for (i = 0; i < get_input (); i++)
73 if (middleman_2 (&b, get_input ()) != 3)
74 abort ();
75 return 0;
76 }
77
78 /* { dg-final { scan-ipa-dump "Discovered a virtual call to a known target.*B::.*foo" "inline" } } */
79 /* { dg-final { scan-ipa-dump "B::foo\[^\\n\]*inline copy in int main" "inline" } } */