Eigen with -O3 warning: argument 1 value ‘X’ exceeds maximum object size Y

≡放荡痞女 提交于 2019-12-10 17:14:50

问题


What happens

When I try to add an Eigen::Vector3f into an std::vector following the tutorial on Eigen website like this:

#include <Eigen/Core>
#include <Eigen/StdVector>
#include <iostream>

template <class EigenT>
using EigenStdVector = std::vector<EigenT, Eigen::aligned_allocator<EigenT>>;

int main() {
  EigenStdVector<Eigen::Vector3f> vec;
  vec.emplace_back(1.0f, 1.0f, 1.0f);
  std::cerr << vec.back().transpose() << std::endl;
  return 0;
}

I get the following warning:

In file included from /usr/include/eigen3/Eigen/Core:349:0,
                 from /home/igor/Code/eigen_example/example.cpp:3:
In function ‘void* Eigen::internal::aligned_malloc(std::size_t)’,
    inlined from ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {float, float, float}; _Tp = Eigen::Matrix<float, 3, 1>; _Alloc = Eigen::aligned_allocator<Eigen::Matrix<float, 3, 1> >]’ at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:742:76:
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:159:12: warning: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
     result = std::malloc(size);

How to reproduce

I am on Ubuntu 18.04 and have Eigen 3.3.4 installed.

You can build the code in this question with the following command if you have Eigen installed with the following command:

g++ -I/usr/include/eigen3 -O3 example.cpp

What triggers the warning

  • The warning only shows when using Vector2f, Vector3f, etc. It is not shown for types like Matrix2f, Matrix3f, etc.
  • The warning is shown whenever I have -O[1-3] enabled and does not happen with -O0

Further info:

This question seems to be related, but I don't see how it could help me.

I have made a small example for everyone who wants a ready-to-run example. You can find it on my GitHub.

Does anybody have an idea what might be wrong here?


回答1:


In the file Eigen/src/Core/util/Memory.h in the implementation of Eigen::aligned_allocator these lines can be found:

#if EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_AT_LEAST(7,0)
// In gcc std::allocator::max_size() is bugged making gcc triggers a warning:
// eigen/Eigen/src/Core/util/Memory.h:189:12: warning: argument 1 value '18446744073709551612' exceeds maximum object size 9223372036854775807
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87544
size_type max_size() const {
  return (std::numeric_limits<std::ptrdiff_t>::max)()/sizeof(T);
}
#endif

So, it seems that this is connected to this GCC bug.

As far as I can see, the commit fixing this appeared on 2018-10-07, and should be available in Eigen 3.3.6.



来源:https://stackoverflow.com/questions/53933092/eigen-with-o3-warning-argument-1-value-x-exceeds-maximum-object-size-y

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!