Debian Codegraph @

gcc/testsuite/g++.dg/ipa/devirt-43.C

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O3 -fdump-ipa-inline-details -fno-ipa-cp -fno-early-inlining" } */
3 struct A {virtual int foo () {return 1;}};
4 struct B {int i; struct A a;};
5 struct C:A {virtual int foo () {return 2;}};
6
7 void dostuff(struct A *);
8
9 static void
10 test (struct A *a)
11 {
12 dostuff (a);
13 if (a->foo ()!= 2)
14 __builtin_abort ();
15 }
16
17 void
18 t(struct B *b)
19 {
20 test(&b->a);
21 }
22 /* Here b comes externally, but we take speculative hint from type of the pointer that it is
23 of type B. This makes A fully specified and we know C::foo is unlikely.
24 FIXME: We could most probably can devirtualize unconditonally because dereference of b in
25 &b->a makes the type known. GIMPLE does not represent this. */
26 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a speculative target" 1 "inline" { xfail *-*-* } } } */