view gcc/testsuite/g++.dg/ipa/devirt-43.C @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* { dg-do compile } */
/* { dg-options "-O3 -fdump-ipa-inline-details -fno-ipa-cp -fno-early-inlining" } */
struct A {virtual int foo () {return 1;}};
struct B {int i; struct A a;};
struct C:A {virtual int foo () {return 2;}};

void dostuff(struct A *);

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

void
t(struct B *b)
{
  test(&b->a);
}
/* Here b comes externally, but we take speculative hint from type of the pointer that it is
   of type B.  This makes A fully specified and we know C::foo is unlikely.
   FIXME: We could most probably can devirtualize unconditonally because dereference of b in
   &b->a makes the type known.  GIMPLE does not represent this.  */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a speculative target" 1 "inline" { xfail *-*-* } } } */