OSDN Git Service

PR debug/43942
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / otr-fold-2.C
1 /* Verify that virtual calls are folded even when a typecast to an
2    ancestor is involved along the way.  */
3 /* { dg-do run } */
4 /* { dg-options "-O -fdump-tree-optimized-slim"  } */
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 A_2 : public A
29 {
30 public:
31   int data_2;
32   virtual int baz (int i);
33 };
34
35
36 class B : public Distraction, public A_2
37 {
38 public:
39   virtual int foo (int i);
40 };
41
42 float Distraction::bar (float z)
43 {
44   f += z;
45   return f/2;
46 }
47
48 int A::foo (int i)
49 {
50   return i + 1;
51 }
52
53 int A_2::baz (int i)
54 {
55   return i * 15;
56 }
57
58 int B::foo (int i)
59 {
60   return i + 2;
61 }
62
63 int __attribute__ ((noinline,noclone)) get_input(void)
64 {
65   return 1;
66 }
67
68 static inline int middleman_1 (class A *obj, int i)
69 {
70   return obj->foo (i);
71 }
72
73 static inline int middleman_2 (class A *obj, int i)
74 {
75   return middleman_1 (obj, i);
76 }
77
78 int main (int argc, char *argv[])
79 {
80   class B b;
81
82   if (middleman_2 (&b, get_input ()) != 3)
83     abort ();
84   return 0;
85 }
86
87 /* { dg-final { scan-tree-dump "= B::foo"  "optimized"  } } */
88 /* { dg-final { cleanup-tree-dump "optimized" } } */