summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/tree-ssa/pr19786.C
blob: faaecdfd97174aa82376b6d67a574a7e459785d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// { dg-do run }
/* { dg-options "-O2" } */

// We used to get alias grouping wrong on this one, hoisting accesses
// to the vector's end out of the loop.

#include <vector>
#include <cassert>

struct A
{
  double unused;      // If I remove it => it works.
  std::vector<int> v;

  A() : v(1) {}
};

inline // If not inline => it works.
A g()
{
  A r;
  r.v.resize(2);
  r.v[0] = 1;

  while (!r.v.empty() && r.v.back() == 0)
    r.v.pop_back();

  return r;
}

A f(const A &a)
{
  if (a.v.empty())  return a;
  if (a.v.empty())  return a;

  // A z = g(); return z;  // If I return like this => it works.
  return g();
}

int main()
{
  A a;
  A b;
  A r = f(a);
  assert(r.v.size() != 0);

  return 0;
}