Skip to content

Commit 47839ba

Browse files
committed
add some debug asserts; won't normally run but may save someone a headache one day
1 parent f6313e8 commit 47839ba

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

library/core/src/intrinsics/simd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T {
2929
#[rustc_nounwind]
3030
#[cfg(not(bootstrap))]
3131
pub unsafe fn simd_insert_dyn<T, U>(mut x: T, idx: u32, val: U) -> T {
32+
debug_assert!((idx as usize) < core::mem::size_of::<T>() / core::mem::size_of::<U>());
3233
// SAFETY: `idx` must be in-bounds
3334
unsafe { (&mut x as *mut T as *mut U).add(idx as usize).write(val) }
3435
x
@@ -61,6 +62,7 @@ pub unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U {
6162
#[rustc_nounwind]
6263
#[cfg(not(bootstrap))]
6364
pub unsafe fn simd_extract_dyn<T, U>(x: T, idx: u32) -> U {
65+
debug_assert!((idx as usize) < core::mem::size_of::<T>() / core::mem::size_of::<U>());
6466
// SAFETY: `idx` must be in-bounds
6567
unsafe { (&x as *const T as *const U).add(idx as usize).read() }
6668
}

0 commit comments

Comments
 (0)