Wattributes-10.c: Add -fno-common option on hppa*-*-hpux*.
[official-gcc.git] / gcc / testsuite / g++.dg / ipa / devirt-4.C
blob6b8a12ab0fdca30eece568f456872ff812861e7b
1 /* Verify that ipa-co can convert virtual calls to direct ones even
2    when a typecast to an ancestor is involved along the way.  */
3 /* { dg-do run } */
4 /* { dg-options "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized"  } */
6 extern "C" void abort (void);
8 class A
10 public:
11   int data;
12   virtual int foo (int i);
15 class B : public A
17 public:
18   virtual int foo (int i);
21 class C : public A
23 public:
24   virtual int foo (int i);
27 int A::foo (int i)
29   return i + 1;
32 int B::foo (int i)
34   return i + 2;
37 int C::foo (int i)
39   return i + 3;
42 int __attribute__ ((noinline,noclone)) get_input(void)
44   return 1;
47 static int middleman_1 (class A *obj, int i)
49   return obj->foo (i);
52 static int middleman_2 (class B *obj, int i)
54   return middleman_1 (obj, i);
57 int main (int argc, char *argv[])
59   class B b;
60   if (middleman_2 (&b, get_input ()) != 3)
61     abort ();
62   return 0;
65 /* { dg-final { scan-ipa-dump "Discovered a virtual call to a known target.*B::foo"  "cp"  } } */
66 /* { dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 0 "optimized"} } */