| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O3 -fno-early-inlining -fno-ipa-sra -fdump-ipa-cp" } */ |
| 3 |
class A {}; |
| 4 |
class B { |
| 5 |
public: |
| 6 |
A &operator[](int); |
| 7 |
}; |
| 8 |
class C : B { |
| 9 |
public: |
| 10 |
virtual int m_fn1() { return 0; } |
| 11 |
A &operator[](int p1) { |
| 12 |
int a; |
| 13 |
a = m_fn1(); |
| 14 |
static_cast<void>(__builtin_expect(a, 0) ?: 0); |
| 15 |
return B::operator[](p1); |
| 16 |
} |
| 17 |
}; |
| 18 |
|
| 19 |
C b; |
| 20 |
int *e; |
| 21 |
static void sort(C &p1, C &p2) { |
| 22 |
for (int i=0;; i++) { |
| 23 |
A c, d = p2[0]; |
| 24 |
p1[0] = c; |
| 25 |
p2[0] = d; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
void lookupSourceDone() { b[0]; } |
| 30 |
|
| 31 |
void update_sources() { |
| 32 |
if (e) { |
| 33 |
C f; |
| 34 |
sort(f, b); |
| 35 |
} |
| 36 |
} |
| 37 |
/* Note that we miss one devirtualization because we are not able to track the |
| 38 |
vtbl store in destructor. |
| 39 |
Previously we devirtualized to C::m_fn1 instead of B::m_fn1. */ |
| 40 |
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 2 "cp" } } */ |