Fix unsafe use of EIGEN_ALIGN_MAX for aligned-packet data

Use EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) instead of EIGEN_ALIGN_MAX for aligning arrays used in packet operations expecting aligned pointers. EIGEN_ALIGN_MAX expands to nothing when EIGEN_MAX_STATIC_ALIGN_BYTES <= 01, creating a segfault hazard.

Changes:

  • Fix bug that TensorFixedSize advertises IsAligned for any positive EIGEN_MAX_ALIGN_BYTES while it is only usable soundly by TensorAssignOp for EIGEN_MAX_STATIC_ALIGN_BYTES >= 16: the latter assumes alignment Aligned (== Aligned16) when a tensor expression advertises IsAligned2.

-----BEGIN LLM TEXT-----

  • Core: GenericPacketMath.h (partial load/store/gather/scatter), ConcatOp.h, AltiVec/NEON TypeCasting.h, LU/arch/InverseSize4.h.
  • unsupported: AutoDiff/CoherentPadOp.h and the Tensor module (Broadcasting, Chipping, Concatenation, ContractionMapper, Conversion, Convolution, Generator, ImagePatch, Inflation, Morphing, Padding, Patch, Random, Reduction, Reverse, Roll, Shuffling, Striding, VolumePatch).
  • TensorFixedSize.h: fix IsAligned to check EIGEN_MAX_STATIC_ALIGN_BYTES instead of EIGEN_MAX_ALIGN_BYTES to correctly reflect alignment imparted by EIGEN_ALIGN_MAX.
  • test/geo_quaternion.cpp: use EIGEN_ALIGN_TO_BOUNDARY(Aligned) for buffers backing Map<Quaternion<Scalar>, Aligned>, since Aligned is a hardcoded constant independent of EIGEN_MAX_STATIC_ALIGN_BYTES.
  • unsupported/test: special_packetmath.cpp and tensor_random.cpp.

Verified by building and running the affected test suites (packetmath, geo_quaternion, geo_hyperplane, geo_parametrizedline, geo_transformations, special_packetmath, tensor_random, and the touched Tensor evaluators) under the default config, under -DEIGEN_MAX_STATIC_ALIGN_BYTES=0 (the previously-broken path), and under that config with -fsanitize=alignment.

-----END LLM TEXT-----

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

  1. https://gitlab.com/libeigen/eigen/-/blob/973c2101506f33ca78ba04e4a24958e137564aeb/Eigen/src/Core/util/ConfigureVectorization.h#L172-L176

  2. https://gitlab.com/libeigen/eigen/-/blob/973c2101506f33ca78ba04e4a24958e137564aeb/unsupported/Eigen/src/Tensor/TensorAssign.h#L154-L155

Edited by onalante-ebay

Merge request reports

Loading