Wmaybe-uninitialized while using Eigen::JacobiSVD

Summary

A warning -Wmaybe-uninitialized is reported while calling singularValues() on an Eigen::JacobiSVD object.

Environment

  • Operating System : Windows --> cross compile for ARM Targets
  • Architecture : Arm
  • Eigen Version : 3.4.0
  • Compiler Version : Gcc11.3.0
  • Compile Flags : -ffreestanding -Wmaybe-uninitialized -O2 -DNDEBUG -std=gnu++17 -DEIGEN_HAS_CXX11_MATH=0
  • Vector Extension :

Minimal Example

https://godbolt.org/z/zP1oeEPaE


#include <iostream>
#include <Eigen/Dense>
using namespace std;

namespace Gmc
{

typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> GmcMatrixXdRowMajor;
typedef Eigen::Matrix<double, 6, 6, Eigen::RowMajor> GmcMatrix6dRowMajor;
static constexpr unsigned int nbrOfJoints = 6;

double testSVD(GmcMatrixXdRowMajor& jacobian)
{
    Eigen::JacobiSVD<
        GmcMatrix6dRowMajor,
        Eigen::DecompositionOptions::ComputeFullU | Eigen::DecompositionOptions::ComputeFullV>
        svd(jacobian);

    double const num1 = svd.singularValues()(nbrOfJoints - 1);
    double const num2 = svd.singularValues()(0);

    return num1 + num2;
}

} 

int main()
{

    Gmc::GmcMatrixXdRowMajor jac{};
    cout << Gmc::testSVD(jac);
 
    return 0;
}

Steps to reproduce

arm-eabi-g++.exe -IC:./libs/eigen -DEIGEN_HAS_CXX11_MATH=0 -ffreestanding -Wmaybe-uninitialized -O2 -DNDEBUG -c Test.cpp -o arm.o

What is the current bug behavior?

A warning is printed

What is the expected correct behavior?

No warning expected

Relevant logs

Test.cpp: In function 'double Gmc::testSVD(Gmc::GmcMatrixXdRowMajor&)':
Test.cpp:20:61: warning: 'svd.Eigen::JacobiSVD<Eigen::Matrix<double, 6, 6, 1, 6, 6>, 20>::<unnamed>.Eigen::SVDBase<Eigen::JacobiSVD<Eigen::Matrix<double, 6, 6, 1, 6, 6>, 20> >::m_singularValues.Eigen::Matrix<double, 6, 1, 0, 6, 1>::<unnamed>.Eigen::PlainObjectBase<Eigen::Matrix<double, 6, 1, 0, 6, 1> >::m_storage.Eigen::DenseStorage<double, 6, 6, 1, 0>::m_data.Eigen::internal::plain_array<double, 6, 0, 16>::array[5]' may be used uninitialized [-Wmaybe-uninitialized]
   20 |     double const num1 = svd.singularValues()(nbrOfJoints - 1);
      |                                                             ^
Test.cpp:18:9: note: 'svd' declared here
   18 |         svd(jacobian);
      |         ^~~
Test.cpp:21:47: warning: '*(const double*)((char*)&svd + offsetof(Eigen::JacobiSVD<Eigen::Matrix<double, 6, 6, 1, 6, 6>, 20>,Eigen::JacobiSVD<Eigen::Matrix<double, 6, 6, 1, 6, 6>, 20>::<unnamed>.Eigen::SVDBase<Eigen::JacobiSVD<Eigen::Matrix<double, 6, 6, 1, 6, 6>, 20> >::m_singularValues.Eigen::Matrix<double, 6, 1, 0, 6, 1>::<unnamed>.Eigen::PlainObjectBase<Eigen::Matrix<double, 6, 1, 0, 6, 1> >::<unnamed>.Eigen::MatrixBase<Eigen::Matrix<double, 6, 1, 0, 6, 1> >::<unnamed>.Eigen::DenseBase<Eigen::Matrix<double, 6, 1, 0, 6, 1> >::<unnamed>.Eigen::DenseCoeffsBase<Eigen::Matrix<double, 6, 1, 0, 6, 1>, 3>::<unnamed>.Eigen::DenseCoeffsBase<Eigen::Matrix<double, 6, 1, 0, 6, 1>, 1>::<unnamed>.Eigen::DenseCoeffsBase<Eigen::Matrix<double, 6, 1, 0, 6, 1>, 0>::<unnamed>))' may be used uninitialized [-Wmaybe-uninitialized]
   21 |     double const num2 = svd.singularValues()(0);
      |                                               ^
Test.cpp:18:9: note: 'svd' declared here
   18 |         svd(jacobian);
      |         ^~~
Edited by robertwallner