summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ipa/devirt-45.C
blob: ce415e7c003b70019eedf143ed08759fcc769441 (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
37
38
39
40
41
/* { dg-do compile } */
/* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining" } */
struct A {
  virtual int foo () {return 1;}
  void wrapfoo () {foo();}
  A() {wrapfoo();}
};
inline void* operator new(__SIZE_TYPE__ s, void* buf) throw() {
   return buf;
}
struct B:A {virtual int foo () {return 2;}};

void dostuff(struct A *);

static void
test2 (struct A *a)
{
  dostuff (a);
  if (a->foo ()!= 2)
    __builtin_abort ();
}

static void
test (struct A *a)
{
  dostuff (a);
  static_cast<B*>(a)->~B();
  new(a) B();
  test2(a);
}

int main()
{
  struct B a;
  dostuff (&a);
  test (&a);
}

/* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 1 "inline"  } } */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline"  } } */