Imported Upstream version 4.7.2
[platform/upstream/gcc48.git] / gcc / testsuite / g++.dg / ipa / ivinline-9.C
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 itself has an ancestor wich is not the
4    primary base class.  */
5 /* { dg-do run } */
6 /* { dg-options "-O3 -fdump-ipa-inline -fno-early-inlining -fno-ipa-cp"  } */
7
8 extern "C" void abort (void);
9
10 class Distraction
11 {
12 public:
13   float f;
14   double d;
15   Distraction ()
16   {
17     f = 8.3;
18     d = 10.2;
19   }
20   virtual float bar (float z);
21 };
22
23 class A
24 {
25 public:
26   int data;
27   virtual int foo (int i);
28 };
29 /*
30 class D2
31 {
32 public:
33   virtual float baz (float z)
34   {
35     abort();
36   }
37 };
38 */
39 class A2 : public Distraction, public A
40 {
41   int i2;
42 };
43
44 class B : public A2
45 {
46 public:
47   virtual int foo (int i);
48 };
49
50 float Distraction::bar (float z)
51 {
52   f += z;
53   return f/2;
54 }
55
56 int A::foo (int i)
57 {
58   return i + 1;
59 }
60
61 int B::foo (int i)
62 {
63   return i + 2;
64 }
65
66 int __attribute__ ((noinline,noclone)) get_input(void)
67 {
68   return 1;
69 }
70
71 static int middleman_1 (class A *obj, int i)
72 {
73   return obj->foo (i);
74 }
75
76 static int middleman_2 (class B *obj, int i)
77 {
78   return middleman_1 (obj, i);
79 }
80
81 int main (int argc, char *argv[])
82 {
83   class B b;
84   int i;
85
86   for (i = 0; i < get_input (); i++)
87     if (middleman_2 (&b, get_input ()) != 3)
88       abort ();
89   return 0;
90 }
91
92 /* { dg-final { scan-ipa-dump "Discovered a virtual call to a known target.*B::.*foo"  "inline"  } } */
93 /* { dg-final { scan-ipa-dump "B::foo\[^\\n\]*inline copy in int main"  "inline"  { xfail *-*-* } } } */
94 /* { dg-final { cleanup-ipa-dump "inline" } } */