GCC Compilation Warning - TriangularMatrixVector.h ‘result’ may be used uninitialized
Summary
- Build warnings occur when building with the code listed below
- The
3.4branch tip (specificallymixingtypestests among others) - The minimal example below
- The
Environment
- Operating System : Arch Linux. Kernel: 6.7.6-arch1-1
- Architecture : x86_64 - Intel i7-8565U
- Eigen Version : 3.3.9
-
Compiler Version :
g++ (GCC) 13.2.1 20230801 - Compile Flags : -std=gnu++17 -O2 -Werror -Wall -Wextra -pedantic -pedantic-errors
- Vector Extension : Intel® SSE4.1, Intel® SSE4.2, Intel® AVX2
Minimal Example
#include <iostream>
#include "Eigen/Dense"
using namespace Eigen;
Matrix3f calculateUnitVectRotation(const Vector3f& a, const Vector3f& b)
{
return Quaternionf().FromTwoVectors(a, b).toRotationMatrix();
}
int main()
{
std::cout << "starting\n";
Vector3f a = Vector3f(0, 0, 1);
Vector3f b = Vector3f(1, 0, 0);
Matrix3f out = Matrix3f::Zero();
out = calculateUnitVectRotation(a, b);
std::cout << out << "\n";
std::cout << "ending\n";
return 0;
}
- Also occurs on the
3.4branch, when compiling tests
Steps to reproduce
Minimal Example Steps
- Assuming the above code is in a file called "main.cpp"
- Assuming the Eigen repository is present as a subdir of the current dir
- Compile with the following:
g++ -c -std=gnu++17 -O2 -Werror -Wall -Wextra -pedantic -pedantic-errors main.cpp -o main.o
- Link with the following:
g++ -lm main.o -o main.bin
3.4 Branch Steps
git clone https://gitlab.com/libeigen/eigen.gitcd eigengit checkout 3.4mkdir build_dircd build_dircmake ..-
make check- Wait for it to begin compiling
mixingtypestests, observe the warnings output
- Wait for it to begin compiling
What is the current bug behavior?
- Warning outputted while compiling
What is the expected correct behavior?
- No warnings when compiling
Relevant logs
Warning Messages
- Below warning is from the minimal example (with
-Werror)
In file included from Eigen/Core:341,
from Eigen/Dense:1,
from main.cpp:2:
Eigen/src/Core/products/TriangularMatrixVector.h: In function ‘static void Eigen::internal::trmv_selector<Mode, 1>::run(const Lhs&, const Rhs&, Dest&, const typename Dest::Scalar&) [with Lhs = Eigen::Transpose<const Eigen::Block<const Eigen::Block<Eigen::Matrix<float, 3, 2, 0, 3, 2>, -1, -1, false>, -1, -1, false> >; Rhs = Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<float, float>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<float>, const Eigen::Matrix<float, 1, -1, 1, 1, 3> >, const Eigen::Transpose<const Eigen::Block<const Eigen::Block<const Eigen::Block<Eigen::Matrix<float, 3, 2, 0, 3, 2>, -1, -1, false>, -1, 1, true>, -1, 1, false> > > >; Dest = Eigen::Transpose<Eigen::Block<Eigen::Block<Eigen::Matrix<float, -1, -1, 1, -1, -1>, 1, -1, true>, 1, -1, false> >; int Mode = 6]’:
Eigen/src/Core/products/TriangularMatrixVector.h:332:12: error: ‘result’ may be used uninitialized [-Werror=maybe-uninitialized]
327 | internal::triangular_matrix_vector_product
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328 | <Index,Mode,
| ~~~~~~~~~~~~
329 | LhsScalar, LhsBlasTraits::NeedToConjugate,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330 | RhsScalar, RhsBlasTraits::NeedToConjugate,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
331 | RowMajor>
| ~~~~~~~~~
332 | ::run(actualLhs.rows(),actualLhs.cols(),
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333 | actualLhs.data(),actualLhs.outerStride(),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334 | actualRhsPtr,1,
| ~~~~~~~~~~~~~~~
335 | dest.data(),dest.innerStride(),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336 | actualAlpha);
| ~~~~~~~~~~~~
Eigen/src/Core/products/TriangularMatrixVector.h:105:24: note: by argument 5 of type ‘const float*’ to ‘static void Eigen::internal::triangular_matrix_vector_product<Index, Mode, LhsScalar, ConjLhs, RhsScalar, ConjRhs, 1, Version>::run(Index, Index, const LhsScalar*, Index, const RhsScalar*, Index, ResScalar*, Index, const ResScalar&) [with Index = long int; int Mode = 6; LhsScalar = float; bool ConjLhs = false; RhsScalar = float; bool ConjRhs = false; int Version = 0]’ declared here
105 | EIGEN_DONT_INLINE void triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,RowMajor,Version>
|
- Below is part of the compilation output (& warning) from running
make check -j1on the3.4branch
[ 4%] Linking CXX executable mixingtypes_2
[ 4%] Built target mixingtypes_2
[ 4%] Building CXX object test/CMakeFiles/mixingtypes_3.dir/mixingtypes.cpp.o
In file included from /home/k.brandt/code/eigen_upgrades/eigen_repo/eigen/Eigen/Core:342,
from /home/k.brandt/code/eigen_upgrades/eigen_repo/eigen/Eigen/QR:11,
from /home/k.brandt/code/eigen_upgrades/eigen_repo/eigen/test/main.h:363,
from /home/k.brandt/code/eigen_upgrades/eigen_repo/eigen/test/mixingtypes.cpp:43:
/home/k.brandt/code/eigen_upgrades/eigen_repo/eigen/Eigen/src/Core/products/TriangularMatrixVector.h: In function ‘static void Eigen::internal::trmv_selector<Mode, 1>::run(const Lhs&, const Rhs&, Dest&, const typename Dest::Scalar&) [with Lhs = Eigen::Transpose<const Eigen::Matrix<double, -1, -1> >; Rhs = Eigen::Transpose<const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<std::complex<double>, std::complex<double> >, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<std::complex<double> >, const Eigen::Matrix<std::complex<double>, 1, -1> >, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<std::complex<double> >, Eigen::Transpose<const Eigen::Matrix<std::complex<double>, -1, 1> > > > >; Dest = Eigen::Transpose<Eigen::Matrix<std::complex<double>, 1, -1> >; int Mode = 2]’:
/home/k.brandt/code/eigen_upgrades/eigen_repo/eigen/Eigen/src/Core/products/TriangularMatrixVector.h:332:12: warning: ‘<unknown>’ may be used uninitialized [-Wmaybe-uninitialized]
327 | internal::triangular_matrix_vector_product
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328 | <Index,Mode,
| ~~~~~~~~~~~~
329 | LhsScalar, LhsBlasTraits::NeedToConjugate,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330 | RhsScalar, RhsBlasTraits::NeedToConjugate,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
331 | RowMajor>
| ~~~~~~~~~
332 | ::run(actualLhs.rows(),actualLhs.cols(),
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333 | actualLhs.data(),actualLhs.outerStride(),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334 | actualRhsPtr,1,
| ~~~~~~~~~~~~~~~
335 | dest.data(),dest.innerStride(),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336 | actualAlpha);
| ~~~~~~~~~~~~
Benchmark scripts and results
Anything else that might help
- The codebase I use Eigen in has
-Werroron, so compiling doesn't work unless this warning is explicitly avoided - As far as I can tell, the program functions correctly when compiled with the warning
- Doesn't seem to warn when compiled with
-DEIGEN_NO_MALLOC - Occurs on the following branches
-
masterbranch -
3.4branch -
3.4.0release (iirc) - NOT
3.3.7(iirc)
-
- Doesn't seem to warn when compiled with
- Warnings cropped up when compiling for an ARM chip too
- Compiles completely fine and without warnings on clang
- Might just be a silly GCC thing
- Thank you to the contributors of this repo
- I can see it's used widely as listed on the main page
- It's a very useful project and has enabled a lot of projects
- I appreciate the hard work