annotate gcc/testsuite/g++.dg/ipa/devirt-42.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* { dg-do compile } */
kono
parents:
diff changeset
2 /* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining -fdump-tree-optimized" } */
kono
parents:
diff changeset
3 struct A {
kono
parents:
diff changeset
4 virtual int foo () {return 1;}
kono
parents:
diff changeset
5 int bar () {return foo();}
kono
parents:
diff changeset
6 int barbar ();
kono
parents:
diff changeset
7 };
kono
parents:
diff changeset
8 namespace {
kono
parents:
diff changeset
9 struct B:A {virtual int foo () {return 2;}
kono
parents:
diff changeset
10 int barbar () {return bar();}};
kono
parents:
diff changeset
11 }
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 int
kono
parents:
diff changeset
14 A::barbar()
kono
parents:
diff changeset
15 {
kono
parents:
diff changeset
16 return static_cast<B*>(this)->barbar();
kono
parents:
diff changeset
17 }
kono
parents:
diff changeset
18
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
19 int main()
111
kono
parents:
diff changeset
20 {
kono
parents:
diff changeset
21 struct B b;
kono
parents:
diff changeset
22 struct A *a = &b;
kono
parents:
diff changeset
23 return a->barbar ();
kono
parents:
diff changeset
24 }
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 /* Inlining everything into main makes type clear from type of variable b.
kono
parents:
diff changeset
27 However devirtualization is also possible for offline copy of A::barbar. Invoking
kono
parents:
diff changeset
28 B's barbar makes it clear the type is at least B and B is an anonymous
kono
parents:
diff changeset
29 namespace type and therefore we know it has no derivations. */
kono
parents:
diff changeset
30 /* { dg-final { scan-ipa-dump "First type is base of second" "inline" } } */
kono
parents:
diff changeset
31 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 2 "inline" } } */
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 /* Verify that speculation is optimized by late optimizers. */
kono
parents:
diff changeset
34 /* { dg-final { scan-tree-dump-times "return 2" 3 "optimized" } } */
kono
parents:
diff changeset
35 /* { dg-final { scan-tree-dump-not "OBJ_TYPE_REF" "optimized" } } */
kono
parents:
diff changeset
36