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