Debian Codegraph @

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

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -fdump-ipa-devirt-details -fdump-tree-fre1-details" } */
3 struct A {virtual int t(void) {return 1;}};
4 struct B:A {B(); virtual int t(void) {return 2;}};
5 struct C {int a; struct B b;};
6 void test2(struct A *);
7 int
8 m(struct B *b)
9 {
10 struct C *c = new (C);
11 struct A *a = &c->b;
12 a->t(); // This call should be devirtualized by
13 // FRE because we know type from ctor call
14 ((struct B *)a)->B::t(); // Make devirt possible
15 // C++ FE won't produce inline body without this
16 test2(a);
17 return a->t(); // This call should be devirtualized speculatively because
18 // test2 may change the type of A by placement new.
19 // C++ standard is bit imprecise about this.
20 }
21 /* { dg-final { scan-tree-dump "converting indirect call to function virtual int B::t" "fre1" { target { ! implicit_constexpr } } } } */
22 /* { dg-final { scan-ipa-dump "to virtual int B::t" "devirt" { target { ! implicit_constexpr } } } } */
23 /* { dg-final { scan-ipa-dump "1 speculatively devirtualized" "devirt" } } */
24