From 328b5f90858f93344ebc1484df8cadfd2a5da6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 15 Aug 2023 15:58:41 +0000 Subject: [PATCH] Add temporary macro to allow unaligned scalar UB. --- Eigen/src/Core/MapBase.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 4bd29cf84..20a0154f9 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -193,8 +193,12 @@ template class MapBase EIGEN_DEVICE_FUNC void checkSanity(std::enable_if_t<(internal::traits::Alignment>0),void*> = 0) const { +// Temporary macro to allow scalars to not be properly aligned. This is while we sort out failures +// in TensorFlow Lite that are currently relying on this UB. +#ifndef EIGEN_ALLOW_UNALIGNED_SCALARS // Pointer must be aligned to the Scalar type, otherwise we get UB. eigen_assert((std::uintptr_t(m_data) % alignof(Scalar) == 0) && "data is not scalar-aligned"); +#endif #if EIGEN_MAX_ALIGN_BYTES>0 // innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible value: const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime); @@ -207,7 +211,12 @@ template class MapBase template EIGEN_DEVICE_FUNC void checkSanity(std::enable_if_t::Alignment==0,void*> = 0) const - { eigen_assert((std::uintptr_t(m_data) % alignof(Scalar) == 0) && "data is not scalar-aligned"); } + { +#ifndef EIGEN_ALLOW_UNALIGNED_SCALARS + // Pointer must be aligned to the Scalar type, otherwise we get UB. + eigen_assert((std::uintptr_t(m_data) % alignof(Scalar) == 0) && "data is not scalar-aligned"); +#endif + } PointerType m_data; const internal::variable_if_dynamic m_rows;