From 52d1dd979af688fbf67c34860527b3a4295b7936 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Wed, 6 Jan 2021 13:14:20 -0800 Subject: [PATCH] Fix Ref initialization. Since `eigen_assert` is a macro, the statements can become noops (e.g. when compiling for GPU), so they may not execute the contained logic -- which in this case is the entire `Ref` construction. We need to separate the assert from statements which have consequences. Fixes #2113 --- Eigen/src/Core/Ref.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Eigen/src/Core/Ref.h b/Eigen/src/Core/Ref.h index 00aa45d34..9fca42873 100644 --- a/Eigen/src/Core/Ref.h +++ b/Eigen/src/Core/Ref.h @@ -94,7 +94,7 @@ protected: typedef Stride StrideBase; // Resolves inner stride if default 0. - static Index resolveInnerStride(Index inner) { + static EIGEN_DEVICE_FUNC Index resolveInnerStride(Index inner) { if (inner == 0) { return 1; } @@ -102,7 +102,7 @@ protected: } // Resolves outer stride if default 0. - static Index resolveOuterStride(Index inner, Index outer, Index rows, Index cols, bool isVectorAtCompileTime, bool isRowMajor) { + static EIGEN_DEVICE_FUNC Index resolveOuterStride(Index inner, Index outer, Index rows, Index cols, bool isVectorAtCompileTime, bool isRowMajor) { if (outer == 0) { if (isVectorAtCompileTime) { outer = inner * rows * cols; @@ -311,7 +311,9 @@ template class Ref { EIGEN_STATIC_ASSERT(bool(Traits::template match::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); // Construction must pass since we will not create temprary storage in the non-const case. - eigen_assert(Base::construct(expr.derived())); + const bool success = Base::construct(expr.derived()); + EIGEN_UNUSED_VARIABLE(success) + eigen_assert(success); } template EIGEN_DEVICE_FUNC inline Ref(const DenseBase& expr, @@ -326,7 +328,9 @@ template class Ref EIGEN_STATIC_ASSERT(bool(Traits::template match::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); // Construction must pass since we will not create temporary storage in the non-const case. - eigen_assert(Base::construct(expr.const_cast_derived())); + const bool success = Base::construct(expr.const_cast_derived()); + EIGEN_UNUSED_VARIABLE(success) + eigen_assert(success); } EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref)