This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/69553] [6 Regression] Optimizations O1/O2 makes std::array value incorrect when passed to function
- From: "trippels at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 31 Jan 2016 08:52:03 +0000
- Subject: [Bug middle-end/69553] [6 Regression] Optimizations O1/O2 makes std::array value incorrect when passed to function
- Auto-submitted: auto-generated
- References: <bug-69553-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69553
--- Comment #6 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
markus@x4 tmp % cat array.ii
template <typename _Tp, long _Nm> struct A {
typedef _Tp _Type[_Nm];
static _Tp &_S_ref(const _Type &p1, int p2) {
return const_cast<_Tp &>(p1[p2]);
}
};
template <typename _Tp, long _Nm> struct B {
typedef A<_Tp, _Nm> _AT_Type;
typename _AT_Type::_Type _M_elems;
_Tp &operator[](long p1) const { return _AT_Type::_S_ref(_M_elems, p1); }
};
int t;
void foo(int p1, int &p2) {
if ((t & 1) == 0) {
if (p1 != 1)
__builtin_abort();
if (p2 != 2)
__builtin_abort();
}
t++;
}
__attribute__((noinline))
void test1(const B<int, 2> &p1) { foo(p1[0], p1[1]); }
void test(B<B<int, 2>, 2> &p1) {
test1(p1[0]);
test1(p1[1]);
foo(p1[0][0], p1[0][1]);
}
int main() {
B<B<int, 2>, 2> t;
t[0][0] = 1;
t[0][1] = 2;
test(t);
}