编译器,库或用户错误? eigen ::数组,gcc 12.1,“数组下标[...]部分是在数组范围的外部。
更新到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
读取大小吗?
编辑:可以通过使用array3d
和array2d
来进一步简化示例>在这里。
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);
withb.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论