mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix UB in bool packetmath test.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
431e4a913b
commit
7b87b21910
@@ -376,6 +376,12 @@ struct ptrue_impl {
|
||||
}
|
||||
};
|
||||
|
||||
// For booleans, we can only directly set a valid `bool` value to avoid UB.
|
||||
template <>
|
||||
struct ptrue_impl<bool, void> {
|
||||
static EIGEN_DEVICE_FUNC inline bool run(const bool& /*a*/) { return true; }
|
||||
};
|
||||
|
||||
// For non-trivial scalars, set to Scalar(1) (i.e. a non-zero value).
|
||||
// Although this is technically not a valid bitmask, the scalar path for pselect
|
||||
// uses a comparison to zero, so this should still work in most cases. We don't
|
||||
@@ -458,6 +464,32 @@ struct bit_not {
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a) const { return ~a; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct bit_and<bool> {
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a, const bool& b) const {
|
||||
return a && b;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct bit_or<bool> {
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a, const bool& b) const {
|
||||
return a || b;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct bit_xor<bool> {
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a, const bool& b) const {
|
||||
return a != b;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct bit_not<bool> {
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a) const { return !a; }
|
||||
};
|
||||
|
||||
// Use operators &, |, ^, ~.
|
||||
template <typename T>
|
||||
struct operator_bitwise_helper {
|
||||
|
||||
Reference in New Issue
Block a user