Fix ASAN-detected bugs in Diagonal::data() and array_cwise test

libeigen/eigen!2182

Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
Rasmus Munk Larsen
2026-02-21 21:11:36 -08:00
parent d4077a6e99
commit f52ad04bbb
2 changed files with 7 additions and 2 deletions

View File

@@ -91,8 +91,12 @@ class Diagonal : public internal::dense_xpr_base<Diagonal<MatrixType, DiagIndex_
typedef std::conditional_t<internal::is_lvalue<MatrixType>::value, Scalar, const Scalar> ScalarWithConstIfNotLvalue;
EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() {
return rows() > 0 ? &(m_matrix.coeffRef(rowOffset(), colOffset())) : nullptr;
}
EIGEN_DEVICE_FUNC inline const Scalar* data() const {
return rows() > 0 ? &(m_matrix.coeffRef(rowOffset(), colOffset())) : nullptr;
}
EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index) {
EIGEN_STATIC_ASSERT_LVALUE(MatrixType)

View File

@@ -773,6 +773,7 @@ void comparisons(const ArrayType& m) {
// test bug2966: select did not support some scalar types that forbade implicit conversions from bool
ArrayX<scalar_wrapper> m5(10);
m5.setConstant(scalar_wrapper(0));
m5 = (m5 == scalar_wrapper(0)).select(m5, m5);
}