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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Regression started with r260318

  tree-ssa-sccvn.c (vn_reference_lookup_3): Improve memset handling.

  2018-05-17  Richard Biener  <rguent...@suse.de>

          * tree-ssa-sccvn.c (vn_reference_lookup_3): Improve memset handling.

          * gcc.dg/tree-ssa/ssa-fre-63.c: New testcase.

    From-SVN: r260318



The testcase can be reduced to:

#include <valarray>
#include <vector>
#include <cassert>

int main()
{
    std::vector<std::valarray<int>> v = {{1,1}, {2,2}};
    std::valarray<int> sum(2);
    for (const auto& e : v)
      sum = sum + e;
    assert(sum[0]==3);
    assert(sum[1]==3);
}

This is what std::accumulate does, but it works as expected if you do:

    for (const auto& e : v)
      sum += e;

I'm not sure if sum = sum + e is valid, due to the aliasing rules of valarray.

(the test passes if you use an array of valarray instead of std::vector, or
pointers to valarrays instead of vector iterators, I'm not sure why)

Reply via email to