Compiler, library, or user error? Eigen::Array, GCC 12.1, "array subscript [...] is partly outside array bounds"

Viewed 142

After updating to GCC 12.1, I got a array subscript ‘__m256d_u[0]’ is partly outside array bounds error (or rather warning with -Werror) in my project, so I tried isolating the problem.

Here's an MWE, which I also put on godbolt (vector type is __m512d_u instead, but otherwise it's the same error):

#include <Eigen/Dense>
#include <iostream>

using Eigen::Array;

Array<double, 3, 2> foo(){

    Array<double, 2, 2> a;
    a.setRandom();

    Array<double, 3, 2> b;
    b.col(0).tail(2) = a.col(1);
    // b.col(0).template tail<2>() = a.col(1);

    return b;
}

int main(){
    std::cout << foo() << '\n';
    return 0;
}

Relevant compile options are -Wall -Wextra -Werror -O3 -march=native, and the error message notes note: at offset [16, 24] into object ‘a’ of size 32.

The error does not occur under the following circumstances:

  • on GCC 11.3 or older,
  • when removing -march=native
  • when using -O1 or below
  • when replacing the line b.col(0).tail(2) = a.col(1); with b.col(0).template tail<2>() = a.col(1);

So it looks like GCC sees the 3x2 array and the 2x2 array, and doesn't realise that only two entries are accessed each.

My question now is: Who should this be reported to? GCC, Eigen? Or is it a user bug?

Bonus points for telling me what the 24 in the error note (offset [16, 24]) is. The 16 is the start, is the 24 the read size?

EDIT: Example can be further simplified by using Array3d and Array2d, see here.

0 Answers
Related