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
TensorFixedSizeadvertisesIsAlignedfor any positiveEIGEN_MAX_ALIGN_BYTESwhile it is only usable soundly byTensorAssignOpforEIGEN_MAX_STATIC_ALIGN_BYTES >= 16: the latter assumes alignmentAligned (== Aligned16)when a tensor expression advertisesIsAligned2.
-----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
IsAlignedto checkEIGEN_MAX_STATIC_ALIGN_BYTESinstead ofEIGEN_MAX_ALIGN_BYTESto correctly reflect alignment imparted byEIGEN_ALIGN_MAX. - test/geo_quaternion.cpp: use
EIGEN_ALIGN_TO_BOUNDARY(Aligned)for buffers backingMap<Quaternion<Scalar>, Aligned>, sinceAlignedis a hardcoded constant independent ofEIGEN_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
Edited by onalante-ebay