summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ipa/devirt-42.C
blob: 152b9689dc4d6aff51cbbdada225497ea8ccd406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining -fdump-tree-optimized" } */
struct A {
  virtual int foo () {return 1;}
  int bar () {return foo();}
  int barbar ();
};
namespace {
  struct B:A {virtual int foo () {return 2;}
	      int barbar () {return bar();}};
}

int
A::barbar()
{
  return static_cast<B*>(this)->barbar();
}

int main()
{
  struct B b;
  struct A *a = &b;
  return a->barbar ();
}

/* Inlining everything into main makes type clear from type of variable b.
   However devirtualization is also possible for offline copy of A::barbar. Invoking
   B's barbar makes it clear the type is at least B and B is an anonymous
   namespace type and therefore we know it has no derivations.  */
/* { dg-final { scan-ipa-dump "First type is base of second" "inline"  } } */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 2 "inline"  } } */

/* Verify that speculation is optimized by late optimizers.  */
/* { dg-final { scan-tree-dump-times "return 2" 3 "optimized"  } } */
/* { dg-final { scan-tree-dump-not "OBJ_TYPE_REF" "optimized"  } } */