Add temporary macro to allow unaligned scalar UB.

This commit is contained in:
Antonio Sánchez 2023-08-15 15:58:41 +00:00 committed by Rasmus Munk Larsen
parent a798d07659
commit 328b5f9085

View File

@ -193,8 +193,12 @@ template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
EIGEN_DEVICE_FUNC
void checkSanity(std::enable_if_t<(internal::traits<T>::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<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
template<typename T>
EIGEN_DEVICE_FUNC
void checkSanity(std::enable_if_t<internal::traits<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<Index, RowsAtCompileTime> m_rows;