OSDN Git Service

PR c++/47687
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / ipa / devirt-3.C
1 /* Verify that simple virtual calls on an object refrence are
2    converted to simple calls by ipa-cp.  */
3 /* { dg-do run } */
4 /* { dg-options "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized"  } */
5
6 extern "C" void abort (void);
7
8 class A
9 {
10 public:
11   int data;
12   virtual int foo (int i);
13 };
14
15 class B : public A
16 {
17 public:
18   virtual int foo (int i);
19 };
20
21 class C : public A
22 {
23 public:
24   virtual int foo (int i);
25 };
26
27 int A::foo (int i)
28 {
29   return i + 1;
30 }
31
32 int B::foo (int i)
33 {
34   return i + 2;
35 }
36
37 int C::foo (int i)
38 {
39   return i + 3;
40 }
41
42 static int middleman (class A &obj, int i)
43 {
44   return obj.foo (i);
45 }
46
47 int __attribute__ ((noinline,noclone)) get_input(void)
48 {
49   return 1;
50 }
51
52 int main (int argc, char *argv[])
53 {
54   class B b;
55   if (middleman (b, get_input ()) != 3)
56     abort ();
57   return 0;
58 }
59
60 /* { dg-final { scan-ipa-dump "Discovered a virtual call to a known target.*B::foo"  "cp"  } } */
61 /* { dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 0 "optimized"} } */
62 /* { dg-final { cleanup-ipa-dump "cp" } } */
63 /* { dg-final { cleanup-tree-dump "optimized" } } */