编译器,库或用户错误? eigen ::数组,gcc 12.1,“数组下标[...]部分是在数组范围的外部。

发布于 2025-02-13 05:16:29 字数 1283 浏览 0 评论 0原文

更新到GCC 12.1后,我在我的项目中得到了array subscript'__ m256d_u [0]'部分是外部阵列bunds error(或更确切地说是用werror)在我的项目中,所以我尝试隔离这个问题。

这是MWE,我还将其放在 godbolt (vector类型是__ m512d_u) ,但否则是相同的错误):

#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;
}

相关的编译选项是-wall -wextra -werror -o3 -march =本机,错误消息注释注意:在Offset [16,24]中,大小为32的对象'a'。

在以下情况下,该错误不会发生:

  • 时,在GCC 11.3或以上,
  • 在使用-march =本机
  • 使用-O1或以下
  • 时,替换行b。 。 a.col(1);

因此GCC看来看到了3x2数组和2x2数组,并且没有意识到每个条目都只能访问两个条目。

我现在的问题是:应该向谁报告?海湾合作委员会,特征?还是用户错误?

告诉我错误注释(Offset [16,24])中的24的奖励积分。 16是开始吗,24读取大小吗?

编辑:可以通过使用array3darray2d来进一步简化示例>在这里。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文