.
[official-gcc.git] / gcc / testsuite / g++.dg / ipa / devirt-45.C
blobce415e7c003b70019eedf143ed08759fcc769441
1 /* { dg-do compile } */
2 /* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining" } */
3 struct A {
4   virtual int foo () {return 1;}
5   void wrapfoo () {foo();}
6   A() {wrapfoo();}
7 };
8 inline void* operator new(__SIZE_TYPE__ s, void* buf) throw() {
9    return buf;
11 struct B:A {virtual int foo () {return 2;}};
13 void dostuff(struct A *);
15 static void
16 test2 (struct A *a)
18   dostuff (a);
19   if (a->foo ()!= 2)
20     __builtin_abort ();
23 static void
24 test (struct A *a)
26   dostuff (a);
27   static_cast<B*>(a)->~B();
28   new(a) B();
29   test2(a);
32 int main()
34   struct B a;
35   dostuff (&a);
36   test (&a);
39 /* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */
40 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 1 "inline"  } } */
41 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline"  } } */