From 743c92528639f466eb887655b5f0fa872105326a Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Tue, 5 Nov 2019 19:06:12 +0000 Subject: [PATCH 1/2] test/packetmath: Silence alignment warnings --- test/packetmath.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/packetmath.cpp b/test/packetmath.cpp index 64dd3dbf6..00f5f042b 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -39,9 +39,12 @@ bits(const T& x) { // The following implement bitwise operations on floating point types template T apply_bit_op(Bits a, Bits b, Func f) { - Array res; - for(Index i=0; i(&res); + Array data; + T res; + for(Index i = 0; i < data.size(); ++i) + data[i] = f(a[i], b[i]); + std::memcpy(&res, &data, sizeof(T)); + return res; } #define EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,T) \ From 86eb41f1cb016916d0813da851ec39a244ff6d8f Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Thu, 7 Nov 2019 14:34:06 +0000 Subject: [PATCH 2/2] SparseRef: Fixed alignment warning on ARM GCC --- Eigen/src/Core/util/Meta.h | 10 ++++++++++ Eigen/src/SparseCore/SparseRef.h | 14 +++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index fe9550d71..2153f2c0d 100755 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -612,6 +612,16 @@ template struct scalar_product_traits // typedef typename scalar_product_traits::type, typename remove_all::type>::ReturnType type; // }; +/** \internal Obtains a POD type suitable to use as storage for an object of a size + * of at most Len bytes, aligned as specified by \c Align. + */ +template +struct aligned_storage { + struct type { + EIGEN_ALIGN_TO_BOUNDARY(Align) unsigned char data[Len]; + }; +}; + } // end namespace internal namespace numext { diff --git a/Eigen/src/SparseCore/SparseRef.h b/Eigen/src/SparseCore/SparseRef.h index d91f38f97..748f87d62 100644 --- a/Eigen/src/SparseCore/SparseRef.h +++ b/Eigen/src/SparseCore/SparseRef.h @@ -201,7 +201,7 @@ class Ref, Options, StrideType ~Ref() { if(m_hasCopy) { - TPlainObjectType* obj = reinterpret_cast(m_object_bytes); + TPlainObjectType* obj = reinterpret_cast(&m_storage); obj->~TPlainObjectType(); } } @@ -213,7 +213,7 @@ class Ref, Options, StrideType { if((Options & int(StandardCompressedFormat)) && (!expr.isCompressed())) { - TPlainObjectType* obj = reinterpret_cast(m_object_bytes); + TPlainObjectType* obj = reinterpret_cast(&m_storage); ::new (obj) TPlainObjectType(expr); m_hasCopy = true; Base::construct(*obj); @@ -227,14 +227,14 @@ class Ref, Options, StrideType template void construct(const Expression& expr, internal::false_type) { - TPlainObjectType* obj = reinterpret_cast(m_object_bytes); + TPlainObjectType* obj = reinterpret_cast(&m_storage); ::new (obj) TPlainObjectType(expr); m_hasCopy = true; Base::construct(*obj); } protected: - char m_object_bytes[sizeof(TPlainObjectType)]; + typename internal::aligned_storage::type m_storage; bool m_hasCopy; }; @@ -319,7 +319,7 @@ class Ref, Options, StrideType ~Ref() { if(m_hasCopy) { - TPlainObjectType* obj = reinterpret_cast(m_object_bytes); + TPlainObjectType* obj = reinterpret_cast(&m_storage); obj->~TPlainObjectType(); } } @@ -335,14 +335,14 @@ class Ref, Options, StrideType template void construct(const Expression& expr, internal::false_type) { - TPlainObjectType* obj = reinterpret_cast(m_object_bytes); + TPlainObjectType* obj = reinterpret_cast(&m_storage); ::new (obj) TPlainObjectType(expr); m_hasCopy = true; Base::construct(*obj); } protected: - char m_object_bytes[sizeof(TPlainObjectType)]; + typename internal::aligned_storage::type m_storage; bool m_hasCopy; };