Skip to content

Commit 7071c66

Browse files
committed
COMP: Suppress GCC -Wmaybe-uninitialized false positive on Eigen 5
The warning is purely from the Eigen 5.0.1 update changing instantiation/ inlining. Eigen's own CMakeLists.txt already adds -Wno-maybe-uninitialized for its own builds (line 444, with a comment that GCC 12+ emits false positives), and DisableStupidWarnings.h doesn't cover this one. The fix is to suppress at the ITK consumer site, mirroring Eigen's stance. GCC 13.3 inlines the analytical 3x3 fast path of Eigen 5's SelfAdjointEigenSolver into SymmetricEigenAnalysisFixedDimension:: ComputeEigenValues<3, Matrix<float,3,3>, FixedArray<float,3>, Matrix<float,3,3>>, called transitively from SymmetricSecondRankTensor<float,3>::ComputeEigenValues. GCC's IPA cannot prove the third element of solver.m_eivalues is fully written through Eigen's deeply-templated dispatch and emits [-Wmaybe-uninitialized] on itkSymmetricEigenAnalysis.h:1033 (auto eigenValues = solver.eigenvalues();). Add ITK_GCC_SUPPRESS_Wmaybe_uninitialized macro to itkMacro.h alongside the existing ITK_GCC_SUPPRESS_W* family, and apply ITK_GCC_PRAGMA_PUSH / ITK_GCC_PRAGMA_POP around the affected lines, with // clang-format off/on to preserve the macro layout (clang-format otherwise folds the SUPPRESS macro into the adjacent declaration line and breaks parsing). Verified locally on Apple Silicon arm64 inside a ghcr.io/catthehacker/ubuntu:full-24.04 container (gcc 13.3.0, the same toolchain as the failing CI runner): full ITK build (2539 ninja edges) goes from 2 -Wmaybe-uninitialized warnings on this line to 0.
1 parent a3af97d commit 7071c66

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Modules/Core/Common/include/itkMacro.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ namespace itk
109109
# define ITK_GCC_SUPPRESS_Wfloat_equal ITK_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
110110
# define ITK_GCC_SUPPRESS_Wformat_nonliteral ITK_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
111111
# define ITK_GCC_SUPPRESS_Warray_bounds ITK_PRAGMA(GCC diagnostic ignored "-Warray-bounds")
112+
# define ITK_GCC_SUPPRESS_Wmaybe_uninitialized ITK_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
112113
#else
113114
# define ITK_GCC_PRAGMA_PUSH
114115
# define ITK_GCC_PRAGMA_POP
115116
# define ITK_GCC_SUPPRESS_Wfloat_equal
116117
# define ITK_GCC_SUPPRESS_Wformat_nonliteral
117118
# define ITK_GCC_SUPPRESS_Warray_bounds
119+
# define ITK_GCC_SUPPRESS_Wmaybe_uninitialized
118120
#endif
119121

120122
// For Clang only (and not GCC):

Modules/Core/Common/include/itkSymmetricEigenAnalysis.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,16 @@ class ITK_TEMPLATE_EXPORT SymmetricEigenAnalysisFixedDimension
10291029
}
10301030
}
10311031
using EigenSolverType = Eigen::SelfAdjointEigenSolver<EigenLibMatrixType>;
1032+
// GCC's IPA cannot prove that Eigen 5's analytical 3x3 SelfAdjointEigenSolver
1033+
// fully writes m_eivalues; Eigen's own CMakeLists adds -Wno-maybe-uninitialized
1034+
// for the same reason (see Modules/ThirdParty/Eigen3/.../CMakeLists.txt).
1035+
// clang-format off
1036+
ITK_GCC_PRAGMA_PUSH
1037+
ITK_GCC_SUPPRESS_Wmaybe_uninitialized
10321038
const EigenSolverType solver(inputMatrix, Eigen::EigenvaluesOnly);
10331039
auto eigenValues = solver.eigenvalues();
1040+
ITK_GCC_PRAGMA_POP
1041+
// clang-format on
10341042
if (m_OrderEigenValues == EigenValueOrderEnum::OrderByMagnitude)
10351043
{
10361044
detail::sortEigenValuesByMagnitude(eigenValues, VDimension);

0 commit comments

Comments
 (0)