mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix sanitizer regressions in sparse serializer and packet tests
libeigen/eigen!2319 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
@@ -821,10 +821,24 @@ EIGEN_DEVICE_FUNC inline Packet pset1(const typename unpacket_traits<Packet>::ty
|
||||
template <typename Packet, typename BitsType>
|
||||
EIGEN_DEVICE_FUNC inline Packet pset1frombits(BitsType a);
|
||||
|
||||
template <typename Scalar, std::enable_if_t<std::is_trivially_copyable<Scalar>::value, int> = 0>
|
||||
EIGEN_DEVICE_FUNC inline Scalar pload1_scalar(const Scalar* a) {
|
||||
Scalar scalar;
|
||||
EIGEN_USING_STD(memcpy)
|
||||
memcpy(&scalar, a, sizeof(Scalar));
|
||||
return scalar;
|
||||
}
|
||||
|
||||
template <typename Scalar, std::enable_if_t<!std::is_trivially_copyable<Scalar>::value, int> = 0>
|
||||
EIGEN_DEVICE_FUNC inline Scalar pload1_scalar(const Scalar* a) {
|
||||
return Scalar(*a);
|
||||
}
|
||||
|
||||
/** \internal \returns a packet with constant coefficients \a a[0], e.g.: (a[0],a[0],a[0],a[0]) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC inline Packet pload1(const typename unpacket_traits<Packet>::type* a) {
|
||||
return pset1<Packet>(*a);
|
||||
using Scalar = typename unpacket_traits<Packet>::type;
|
||||
return pset1<Packet>(pload1_scalar<Scalar>(a));
|
||||
}
|
||||
|
||||
/** \internal \returns a packet with elements of \a *from duplicated.
|
||||
@@ -834,7 +848,7 @@ EIGEN_DEVICE_FUNC inline Packet pload1(const typename unpacket_traits<Packet>::t
|
||||
*/
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet ploaddup(const typename unpacket_traits<Packet>::type* from) {
|
||||
return *from;
|
||||
return pload1<Packet>(from);
|
||||
}
|
||||
|
||||
/** \internal \returns a packet with elements of \a *from quadrupled.
|
||||
|
||||
@@ -245,7 +245,8 @@ EIGEN_STRONG_INLINE VectorT load_vector_unaligned(const scalar_type_of_vector_t<
|
||||
|
||||
template <typename VectorT>
|
||||
EIGEN_STRONG_INLINE VectorT load_vector_aligned(const scalar_type_of_vector_t<VectorT>* from) {
|
||||
return *reinterpret_cast<const VectorT*>(assume_aligned<EIGEN_GENERIC_VECTOR_SIZE_BYTES>(from));
|
||||
eigen_assert((std::uintptr_t(from) % alignof(VectorT) == 0) && "load_vector_aligned");
|
||||
return *reinterpret_cast<const VectorT*>(assume_aligned<alignof(VectorT)>(from));
|
||||
}
|
||||
|
||||
template <typename VectorT>
|
||||
@@ -255,7 +256,8 @@ EIGEN_STRONG_INLINE void store_vector_unaligned(scalar_type_of_vector_t<VectorT>
|
||||
|
||||
template <typename VectorT>
|
||||
EIGEN_STRONG_INLINE void store_vector_aligned(scalar_type_of_vector_t<VectorT>* to, const VectorT& from) {
|
||||
*reinterpret_cast<VectorT*>(assume_aligned<EIGEN_GENERIC_VECTOR_SIZE_BYTES>(to)) = from;
|
||||
eigen_assert((std::uintptr_t(to) % alignof(VectorT) == 0) && "store_vector_aligned");
|
||||
*reinterpret_cast<VectorT*>(assume_aligned<alignof(VectorT)>(to)) = from;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
Reference in New Issue
Block a user