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
@@ -382,12 +382,6 @@ struct packetmath_boolean_mask_ops_notcomplex_test<
|
||||
}
|
||||
};
|
||||
|
||||
// Packet16b representing bool does not support ptrue, pandnot or pcmp_eq, since
|
||||
// the scalar path (for some compilers) compute the bitwise and with 0x1 of the
|
||||
// results to keep the value in [0,1].
|
||||
template <>
|
||||
void packetmath_boolean_mask_ops<bool, internal::packet_traits<bool>::type>() {}
|
||||
|
||||
template <typename Scalar, typename Packet, typename EnableIf = void>
|
||||
struct packetmath_minus_zero_add_test {
|
||||
static void run() {}
|
||||
@@ -662,11 +656,11 @@ void packetmath() {
|
||||
{
|
||||
for (int i = 0; i < PacketSize; ++i) {
|
||||
// "if" mask
|
||||
unsigned char v = internal::random<bool>() ? 0xff : 0;
|
||||
char* bytes = (char*)(data1 + i);
|
||||
for (int k = 0; k < int(sizeof(Scalar)); ++k) {
|
||||
bytes[k] = v;
|
||||
}
|
||||
// Note: it's UB to load 0xFF directly into a `bool`.
|
||||
uint8_t v =
|
||||
internal::random<bool>() ? (std::is_same<Scalar, bool>::value ? static_cast<uint8_t>(true) : 0xff) : 0;
|
||||
// Avoid strict aliasing violation by using memset.
|
||||
memset(data1 + i, v, sizeof(Scalar));
|
||||
// "then" packet
|
||||
data1[i + PacketSize] = internal::random<Scalar>();
|
||||
// "else" packet
|
||||
|
||||
Reference in New Issue
Block a user