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

0

8

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.

Unclench answered 5/7, 2022 at 14:26 Comment(6)
What line? Does it report anything else? Is the using scalar = double; relevant?Caundra
Check the godbolt link for all details. Line is #13, i.e. the one mentioned in the last bullet point. using scalar = double; is irrelevant, was just easier for me when creating an MWE from my project. I forgot about it when posting. Now I updated it, now the relevant line is #12Unclench
Just two thoughts: Check the bug reports of GCC and Eigen, maybe you find something in either one. In any case, have you tried using a memory debugger (Valgrind comes to mind) on it? That would be a big indicator that this is actually a bug or a false positive.Caundra
I reported the issue to GCC: gcc.gnu.org/bugzilla/show_bug.cgi?id=106247 and Eigen: gitlab.com/libeigen/eigen/-/issues/2506Sothena
This family of warnings is very unreliable (see the number of bugs linked in gcc.gnu.org/bugzilla/show_bug.cgi?id=56456 for a start...), just ignore/disable them.Lubric
I made a very similar bug report that got instantly closed as a duplicate of a completely unrelated bug: gcc.gnu.org/bugzilla/show_bug.cgi?id=106939Tetchy

© 2022 - 2024 — McMap. All rights reserved.