Skip to content

COMP: Fix GCC -Wmaybe-uninitialized in SymmetricEigenAnalysis column permute#6447

Draft
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-eigen-symmetric-maybe-uninit
Draft

COMP: Fix GCC -Wmaybe-uninitialized in SymmetricEigenAnalysis column permute#6447
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-eigen-symmetric-maybe-uninit

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

GCC 14 emits 66 -Wmaybe-uninitialized warnings that all originate from itk::detail::permuteColumnsWithSortIndices in itkSymmetricEigenAnalysis.h. Forcing the permutation product to materialize with Eigen's .eval() idiom before assignment clears every one of them, with no behavior change.

Root cause

The original line assigns a fixed-size matrix in place from a product with a dynamic-size operand:

eigenVectors = eigenVectors * perm;   // fixed-size matrix = fixed-size matrix * dynamic PermutationMatrix

The product's source type has dynamic columns. After inlining, GCC's -Wmaybe-uninitialized analysis of Eigen's vectorized dense_assignment_loop unroll cannot prove every coefficient of the fixed-size destination is written, so it flags the inlined SSE load / assign_op::assignCoeff store. This is a known Eigen/GCC false positive.

Why .eval()

.eval() materializes the product into a complete temporary first, so the assignment source is a fully-initialized object and the unroll analysis is satisfied.

The idiomatic in-place alternative eigenVectors.applyOnTheRight(perm) was tried and verified to NOT suppress the warnings — it routes through the same fixed-from-dynamic assignment internally. .eval() is the minimal change that actually clears them.

Verification (GCC 14.3, full ccache build)
variant -Wmaybe-uninitialized
original 66
applyOnTheRight(perm) 66 (no effect)
(eigenVectors * perm).eval() 0

Behavior unchanged (same column permutation); the SymmetricEigenAnalysis and transform tests pass.

…permute

GCC 14 emits -Wmaybe-uninitialized warnings (66 instances) that all
originate from itk::detail::permuteColumnsWithSortIndices in
itkSymmetricEigenAnalysis.h. Assigning a fixed-size Eigen::Matrix in
place from a (Matrix * dynamic PermutationMatrix) product leaves GCC's
post-inlining analysis of Eigen's vectorized dense-assignment unroll
unable to prove every coefficient is written -- a documented Eigen/GCC
false positive.

Use the Eigen .eval() idiom to materialize the permutation product into
a temporary before assignment so the assignment source is a complete
object. Column-permutation behavior is unchanged; a full ccache build
drops the count 66 -> 0.
@github-actions github-actions Bot added type:Compiler Compiler support or related warnings area:Core Issues affecting the Core module labels Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Compiler Compiler support or related warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant