Eigen segfault no optimizations Solaris

≡放荡痞女 提交于 2020-01-06 14:12:56

问题


I have the following code:

#include <Eigen/Dense>

struct States 
{
    // Eigen::VectorXd v;
    Eigen::VectorXd v{Eigen::VectorXd::Ones(2)};

    States() {
        // v.resize(2);
        // v << 1, 1;
    }
};

States st;

int main() {}

Whenever I build the project under Solaris 11 (with g++4.9), with no optimizations, I get a segfault (core dumped) when running. After some digging and step-by-step debugging I think the faulty line is in DenseCoeffBase.h, inside function copyPacket, namely the line 537

derived().template writePacket<StoreMode>(index, 
  other.derived().template packet<LoadMode>(index));

Command line I used to compile/run: g++ -std=c++11 -I ./eigen_3.2.2 example.cpp; ./a.out

Some remarks:

  • If I move the declaration States st; inside main(), it works, no segfault.
  • If I uncomment the declaration of v in States and comment the C++11-style initialization, then use v.resize(2); v << 1, 1; inside the constructor, it works
  • If I use -O2 or -O3 optimizations, it works.
  • On all other platforms I tested (Ubuntu 14.04, Debian7, OS X 10.10) it works, no matter the optimization level
  • The problem seems to appear only on Solaris, with no optimizations, under g++4.9

The questions I have are the following:

  1. Is the code I wrote correct? Namely, can I safely use C++11-style in-class initialization, or should I just declare the vector then resize it in the constructor?

  2. If my code is correct, did anyone bumped into this issue? (I know it is highly highly unlikely but I still ask :) )

PS: I use Eigen 3.2.2 (although the issue appears on 3.2.1 also)

I would appreciate if anyone can tell me if can build/run the program on Solaris11 (no matter the compiler)

来源:https://stackoverflow.com/questions/27022190/eigen-segfault-no-optimizations-solaris

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