Skip to content

Commit b6eeb4e

Browse files
Assume masks are correct
This allows miri to detect when they are not, and may be exploited by LLVM during optimization.
1 parent 1273da6 commit b6eeb4e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

crates/core_simd/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const_maybe_uninit_as_mut_ptr,
55
const_mut_refs,
66
convert_float_to_int,
7+
core_intrinsics,
78
decl_macro,
89
inline_const,
910
intra_doc_pointers,

crates/core_simd/src/masks.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ where
175175
#[must_use = "method returns a new mask and does not mutate the original value"]
176176
pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
177177
// Safety: the caller must confirm this invariant
178-
unsafe { Self(mask_impl::Mask::from_int_unchecked(value)) }
178+
unsafe {
179+
core::intrinsics::assume(<T as Sealed>::valid(value));
180+
Self(mask_impl::Mask::from_int_unchecked(value))
181+
}
179182
}
180183

181184
/// Converts a vector of integers to a mask, where 0 represents `false` and -1

0 commit comments

Comments
 (0)