This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/69553] [6 Regression] Optimizations O1/O2 makes std::array value incorrect when passed to function


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69553

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
We go from:
  _3 = &MEM[(const struct array[2] &)t_2(D)][0];
  test1 (_3);
  _5 = &MEM[(const struct array[2] &)t_2(D)][1];
  test1 (_5);
  _7 = &MEM[(const int[2] &)t_2(D)][1];
  foo (_3, _7);
  _9 = &MEM[(const int[2] &)t_2(D) + 8][1];
  foo (_5, _9);

To: 
  _3 = &MEM[(const struct array[2] &)t_2(D)][0];
  test1 (_3);
  _5 = &MEM[(const struct array[2] &)t_2(D)][1];
  test1 (_5);
  foo (_3, _5);
  _9 = &MEM[(const int[2] &)t_2(D) + 8][1];
  foo (_5, _9); [tail call]

I have been trying to remove std::array but I can't.

Here is my current testcase:
#include <array>
typedef int type;
using std::array;
typedef array<array<type, 2>, 2> Matrix;
int t = 0;
void foo(const type &px, const type &py) __attribute__((noinline,noclone));
void foo(const type &px, const type &py)
{
  if ((t&1)==0)
  {
    if (px != 1)
      __builtin_abort ();
    if (py != 2)
      __builtin_abort ();
  } else if (t&1)
  {
    if (px != 3)
      __builtin_abort ();
    if (py != 4)
      __builtin_abort ();
  }
  t++;
}
void test1 (const array<type, 2>& p)  __attribute__((noinline, noclone));
void test1 (const array<type, 2>& p)
{
  foo(p[0], p[1]);
}
void test (const Matrix& t) __attribute__((noinline, noclone));
void test (const Matrix& t)
{
  test1 (t[0]);
  test1 (t[1]);
  foo(t[0][0], t[0][1]);
  foo(t[1][0], t[1][1]);
}
int main (int, char**)
{
  Matrix t;
  t[0][0] = 1;
  t[0][1] = 2;
  t[1][0] = 3;
  t[1][1] = 4;
  test (t);
  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]