Alignment assert due to Eigen::Quaternion and SIMD vectorization in gcc 7.5
I have a class that contains an object of Eigen::Quaterniond indirectly (it is part of Sophus::SE3d). When I want to create a smart pointer of this class, I am getting the segmentation fault due to assert raise of initialization of Quaternion. The assertion is coming from the famous alignment assertion, but the point is that the reason of that is not clear for me.
Eigen/src/Core/DenseStorage.h:128: Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 32>::plain_array() [with T = double; int Size = 4; int MatrixOrArrayOptions = 0]: Assertion `(internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (31)) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"' failed.
Code of class
class Frame final
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Sophus::SE3d m_absolutePose;
Eigen::Matrix< double, 6, 6 > m_covPose;
bool m_keyFrame;
}
Compiler Setting:
- System: Ubuntu 18.04
- Compiler: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
- Vectorization flag: -march=native
- C++ version: c++14
- Eigen version: tested with both 3.3.8 and 3.3.9
- Build type: tested with Release, RelWithDebInfo, Debug
Call stack with GDB:
Thread 1 "vo_app" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007ffff583c921 in __GI_abort () at abort.c:79
#2 0x00007ffff582c48a in __assert_fail_base (fmt=0x7ffff59b3750 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x555556fe0ef0 "(internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (31)) == 0 && \"this assertion is explained here: \" \"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.htm"...,
file=file@entry=0x555556fe0e88 "/home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/eigen/Eigen/src/Core/DenseStorage.h", line=line@entry=128,
function=function@entry=0x555556fe1340 <Eigen::internal::plain_array<double, 4, 0, 32>::plain_array()::__PRETTY_FUNCTION__> "Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 32>::plain_array() [with T = double; int Size = 4; int MatrixOrArrayOptions = 0]") at assert.c:92
#3 0x00007ffff582c502 in __GI___assert_fail (assertion=0x555556fe0ef0 "(internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (31)) == 0 && \"this assertion is explained here: \" \"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.htm"...,
file=0x555556fe0e88 "/home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/eigen/Eigen/src/Core/DenseStorage.h", line=128,
function=0x555556fe1340 <Eigen::internal::plain_array<double, 4, 0, 32>::plain_array()::__PRETTY_FUNCTION__> "Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 32>::plain_array() [with T = double; int Size = 4; int MatrixOrArrayOptions = 0]") at assert.c:101
#4 0x0000555555594c4d in Eigen::internal::plain_array<double, 4, 0, 32>::plain_array (this=0x55555766a770) at /home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/eigen/Eigen/src/Core/DenseStorage.h:128
#5 0x0000555555591e14 in Eigen::DenseStorage<double, 4, 4, 1, 0>::DenseStorage (this=0x55555766a770) at /home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/eigen/Eigen/src/Core/DenseStorage.h:187
#6 0x000055555558ee74 in Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 1, 0, 4, 1> >::PlainObjectBase (this=0x55555766a770) at /home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/eigen/Eigen/src/Core/PlainObjectBase.h:484
#7 0x000055555560d021 in Eigen::Matrix<double, 4, 1, 0, 4, 1>::Matrix (this=0x55555766a770) at /home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/eigen/Eigen/src/Core/Matrix.h:259
#8 0x0000555555606004 in Eigen::Quaternion<double, 0>::Quaternion<Eigen::Matrix<double, 3, 3, 0, 3, 3> > (this=0x55555766a770, other=...) at /home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/eigen/Eigen/src/Geometry/Quaternion.h:290
#9 0x00005555555ffcdc in Sophus::SO3<double, 0>::SO3 (this=0x55555766a770, R=...) at /home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/sophus/include/sophus/so3.hpp:471
#10 0x00005555555fb9f9 in Sophus::SE3<double, 0>::SE3 (this=0x55555766a770, rotation_matrix=..., translation=...) at /home/aabouee/Workspace/cplusplus/vo_360_vp/thirdparty/unx64/sophus/include/sophus/se3.hpp:484
#11 0x00005555556dc0a7 in Frame::Frame (this=0x55555766a770, camera=std::shared_ptr<Camera> (use count 2, weak count 0) = {...}, img=..., maxImagePyramid=4, timestamp=1594809543284619000) at /home/aabouee/Workspace/cplusplus/vo_360_vp/src/cpp_packages/dnae_vo/src/frame.cpp:23
#12 0x00005555555ab026 in __gnu_cxx::new_allocator<Frame>::construct<Frame, std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> (this=0x7fffffffd1c7, __p=0x55555766a770) at /usr/include/c++/7/ext/new_allocator.h:136
#13 0x00005555555aa1bc in std::allocator_traits<std::allocator<Frame> >::construct<Frame, std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> (__a=..., __p=0x55555766a770) at /usr/include/c++/7/bits/alloc_traits.h:475
#14 0x00005555555a8c01 in std::_Sp_counted_ptr_inplace<Frame, std::allocator<Frame>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> (this=0x55555766a750, __a=...) at /usr/include/c++/7/bits/shared_ptr_base.h:526
#15 0x00005555555a736c in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Frame, std::allocator<Frame>, std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> (this=0x7fffffffd468, __a=...) at /usr/include/c++/7/bits/shared_ptr_base.h:637
#16 0x00005555555a4ed1 in std::__shared_ptr<Frame, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<Frame>, std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> (this=0x7fffffffd460, __tag=..., __a=...) at /usr/include/c++/7/bits/shared_ptr_base.h:1295
#17 0x00005555555a3035 in std::shared_ptr<Frame>::shared_ptr<std::allocator<Frame>, std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> (this=0x7fffffffd460, __tag=..., __a=...) at /usr/include/c++/7/bits/shared_ptr.h:344
#18 0x00005555555a143c in std::allocate_shared<Frame, std::allocator<Frame>, std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> (__a=...) at /usr/include/c++/7/bits/shared_ptr.h:691
#19 0x000055555559fc91 in std::make_shared<Frame, std::shared_ptr<Camera>&, cv::Mat const&, int, unsigned long const&> () at /usr/include/c++/7/bits/shared_ptr.h:707
Regarding the assertion page, To solve the case No 1, I added the EIGEN_MAKE_ALIGNED_OPERATOR_NEW on top of public, and I think the case No. 4 also is not the reason, because I have the GCC on Ubuntu?