Fix template.
[official-gcc.git] / gcc / testsuite / g++.dg / ipa / devirt-42.C
blobd7b1b3cd7b3bcbc428607db6903f4921c9576bd2
1 /* { dg-do compile } */
2 /* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining -fdump-tree-optimized" } */
3 struct A {
4   virtual int foo () {return 1;}
5   int bar () {return foo();}
6   int barbar ();
7 };
8 namespace {
9   struct B:A {virtual int foo () {return 2;}
10               int barbar () {return bar();}};
13 int
14 A::barbar()
16   return static_cast<B*>(this)->barbar();
19 main()
21   struct B b;
22   struct A *a = &b;
23   return a->barbar ();
26 /* Inlining everything into main makes type clear from type of variable b.
27    However devirtualization is also possible for offline copy of A::barbar. Invoking
28    B's barbar makes it clear the type is at least B and B is an anonymous
29    namespace type and therefore we know it has no derivations.  */
30 /* { dg-final { scan-ipa-dump "First type is base of second" "inline"  } } */
31 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 2 "inline"  } } */
33 /* Verify that speculation is optimized by late optimizers.  */
34 /* { dg-final { scan-tree-dump-times "return 2" 3 "optimized"  } } */
35 /* { dg-final { scan-tree-dump-not "OBJ_TYPE_REF" "optimized"  } } */
37 /* { dg-final { cleanup-ipa-dump "inline" } } */
38 /* { dg-final { cleanup-tree-dump "optimized" } } */