| 1 |
// { dg-do run } |
| 2 |
/* { dg-options "-O2" } */ |
| 3 |
/* { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } } */ |
| 4 |
|
| 5 |
// We used to get alias grouping wrong on this one, hoisting accesses |
| 6 |
// to the vector's end out of the loop. |
| 7 |
|
| 8 |
#include <vector> |
| 9 |
#include <cassert> |
| 10 |
|
| 11 |
struct A |
| 12 |
{ |
| 13 |
double unused; // If I remove it => it works. |
| 14 |
std::vector<int> v; |
| 15 |
|
| 16 |
A() : v(1) {} |
| 17 |
}; |
| 18 |
|
| 19 |
inline // If not inline => it works. |
| 20 |
A g() |
| 21 |
{ |
| 22 |
A r; |
| 23 |
r.v.resize(2); |
| 24 |
r.v[0] = 1; |
| 25 |
|
| 26 |
while (!r.v.empty() && r.v.back() == 0) |
| 27 |
r.v.pop_back(); |
| 28 |
|
| 29 |
return r; |
| 30 |
} |
| 31 |
|
| 32 |
A f(const A &a) |
| 33 |
{ |
| 34 |
if (a.v.empty()) return a; |
| 35 |
if (a.v.empty()) return a; |
| 36 |
|
| 37 |
// A z = g(); return z; // If I return like this => it works. |
| 38 |
return g(); |
| 39 |
} |
| 40 |
|
| 41 |
int main() |
| 42 |
{ |
| 43 |
A a; |
| 44 |
A b; |
| 45 |
A r = f(a); |
| 46 |
assert(r.v.size() != 0); |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |