mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-07 18:27:40 +08:00
Fix stack allocation assert
This commit is contained in:
parent
3f067c4850
commit
37563856c9
@ -27,42 +27,49 @@ namespace Eigen {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename T, int Size>
|
||||
struct check_static_allocation_size {
|
||||
#if EIGEN_STACK_ALLOCATION_LIMIT
|
||||
EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG)
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
|
||||
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
|
||||
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment)
|
||||
#else
|
||||
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
|
||||
eigen_assert((internal::is_constant_evaluated() || (std::uintptr_t(array) & (sizemask)) == 0) && \
|
||||
"this assertion is explained here: " \
|
||||
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
|
||||
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment) \
|
||||
eigen_assert((internal::is_constant_evaluated() || (std::uintptr_t(array) % Alignment == 0)) && \
|
||||
"this assertion is explained here: " \
|
||||
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
|
||||
" **** READ THIS WEB PAGE !!! ****");
|
||||
#endif
|
||||
|
||||
#if EIGEN_STACK_ALLOCATION_LIMIT
|
||||
#define EIGEN_MAKE_STACK_ALLOCATION_ASSERT(X) \
|
||||
EIGEN_STATIC_ASSERT(X <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG)
|
||||
#else
|
||||
#define EIGEN_MAKE_STACK_ALLOCATION_ASSERT(X)
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned:
|
||||
* to 16 bytes boundary if the total size is a multiple of 16 bytes.
|
||||
*/
|
||||
template <typename T, int Size, int MatrixOrArrayOptions,
|
||||
int Alignment = (MatrixOrArrayOptions & DontAlign) ? 0 : compute_default_alignment<T, Size>::value>
|
||||
struct plain_array : check_static_allocation_size<T, Size> {
|
||||
struct plain_array {
|
||||
EIGEN_ALIGN_TO_BOUNDARY(Alignment) T array[Size];
|
||||
#if defined(EIGEN_NO_DEBUG) || defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
|
||||
#if defined(EIGEN_NO_DEBUG) || defined(EIGEN_TESTING_PLAINOBJECT_CTOR)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() = default;
|
||||
#else
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment - 1); }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() {
|
||||
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment)
|
||||
EIGEN_MAKE_STACK_ALLOCATION_ASSERT(Size * sizeof(T))
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename T, int Size, int MatrixOrArrayOptions>
|
||||
struct plain_array<T, Size, MatrixOrArrayOptions, 0> : check_static_allocation_size<T, Size> {
|
||||
struct plain_array<T, Size, MatrixOrArrayOptions, 0> {
|
||||
T array[Size];
|
||||
#if defined(EIGEN_NO_DEBUG) || defined(EIGEN_TESTING_PLAINOBJECT_CTOR)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() = default;
|
||||
#else
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() { EIGEN_MAKE_STACK_ALLOCATION_ASSERT(Size * sizeof(T)) }
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename T, int MatrixOrArrayOptions, int Alignment>
|
||||
@ -84,7 +91,7 @@ struct DenseStorageIndices {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * Cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void set(Index /*rows*/, Index /*cols*/) {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorageIndices& /*other*/) noexcept {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseStorageIndices& /*other*/) noexcept {}
|
||||
};
|
||||
template <int Rows>
|
||||
struct DenseStorageIndices<Rows, Dynamic> {
|
||||
@ -95,11 +102,11 @@ struct DenseStorageIndices<Rows, Dynamic> {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(DenseStorageIndices&&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(const DenseStorageIndices&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(DenseStorageIndices&&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorageIndices(Index /*rows*/, Index cols) : m_cols(cols) {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(Index /*rows*/, Index cols) : m_cols(cols) {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const { return m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return Rows * m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set(Index /*rows*/, Index cols) { m_cols = cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void set(Index /*rows*/, Index cols) { m_cols = cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseStorageIndices& other) noexcept {
|
||||
numext::swap(m_cols, other.m_cols);
|
||||
}
|
||||
@ -113,11 +120,11 @@ struct DenseStorageIndices<Dynamic, Cols> {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(DenseStorageIndices&&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(const DenseStorageIndices&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(DenseStorageIndices&&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorageIndices(Index rows, Index /*cols*/) : m_rows(rows) {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const { return m_rows; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(Index rows, Index /*cols*/) : m_rows(rows) {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_rows * Cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set(Index rows, Index /*cols*/) { m_rows = rows; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * Cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void set(Index rows, Index /*cols*/) { m_rows = rows; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseStorageIndices& other) noexcept {
|
||||
numext::swap(m_rows, other.m_rows);
|
||||
}
|
||||
@ -132,11 +139,12 @@ struct DenseStorageIndices<Dynamic, Dynamic> {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(DenseStorageIndices&&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(const DenseStorageIndices&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(DenseStorageIndices&&) = default;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorageIndices(Index rows, Index cols) : m_rows(rows), m_cols(cols) {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const { return m_rows; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const { return m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_rows * m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set(Index rows, Index cols) {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(Index rows, Index cols)
|
||||
: m_rows(rows), m_cols(cols) {}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * m_cols; }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void set(Index rows, Index cols) {
|
||||
m_rows = rows;
|
||||
m_cols = cols;
|
||||
}
|
||||
|
@ -9,11 +9,6 @@
|
||||
|
||||
#define EIGEN_TESTING_PLAINOBJECT_CTOR
|
||||
|
||||
#ifndef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
|
||||
#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
|
||||
#define EIGEN_TEST_REENABLE_UNALIGNED_ARRAY_ASSERT
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
#include "AnnoyingScalar.h"
|
||||
#include "SafeScalar.h"
|
||||
@ -32,12 +27,13 @@ static_assert(std::is_trivially_copyable<DenseStorageD3x3>::value, "DenseStorage
|
||||
#endif
|
||||
|
||||
static_assert(std::is_trivially_move_constructible<Matrix4f>::value, "Matrix4f not trivially_move_constructible");
|
||||
static_assert(std::is_trivially_move_constructible<Array4f>::value, "Array4f not trivially_move_constructible");
|
||||
#if !defined(EIGEN_DENSE_STORAGE_CTOR_PLUGIN)
|
||||
static_assert(std::is_trivially_copy_constructible<Matrix4f>::value, "Matrix4f not trivially_copy_constructible");
|
||||
static_assert(std::is_trivially_copy_constructible<Array4f>::value, "Array4f not trivially_copy_constructible");
|
||||
#endif
|
||||
#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
|
||||
static_assert(std::is_trivially_default_constructible<Matrix4f>::value, "Matrix4f not trivially_default_constructible");
|
||||
#endif
|
||||
static_assert(std::is_trivially_default_constructible<Array4f>::value, "Array4f not trivially_default_constructible");
|
||||
|
||||
template <typename T, int Size, int Rows, int Cols>
|
||||
void dense_storage_copy(int rows, int cols) {
|
||||
@ -197,7 +193,3 @@ EIGEN_DECLARE_TEST(dense_storage) {
|
||||
}
|
||||
|
||||
#undef EIGEN_TESTING_PLAINOBJECT_CTOR
|
||||
#ifdef EIGEN_TEST_REENABLE_UNALIGNED_ARRAY_ASSERT
|
||||
#undef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
|
||||
#undef EIGEN_TEST_REENABLE_UNALIGNED_ARRAY_ASSERT
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user