Skip to content

Commit 0145321

Browse files
authored
Rollup merge of #97707 - Nilstrieb:data-structures-ub, r=cjgillot
Improve soundness of rustc_data_structures Make it runnable in miri by adding some ignores and changing N in miri. Also fix a stacked borrows issue in sip128.
2 parents 36a16be + 7e3bee6 commit 0145321

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

compiler/rustc_data_structures/src/base_n/tests.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ fn test_encode() {
1515
test(u64::MAX as u128, base);
1616
test(u128::MAX, base);
1717

18-
for i in 0..1_000 {
18+
const N: u128 = if cfg!(miri) { 10 } else { 1000 };
19+
20+
for i in 0..N {
1921
test(i * 983, base);
2022
}
2123
}

compiler/rustc_data_structures/src/graph/scc/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ fn test_deep_linear() {
156156
v
157157
158158
*/
159+
#[cfg(not(miri))]
159160
const NR_NODES: usize = 1 << 14;
161+
#[cfg(miri)]
162+
const NR_NODES: usize = 1 << 3;
160163
let mut nodes = vec![];
161164
for i in 1..NR_NODES {
162165
nodes.push((i - 1, i));

compiler/rustc_data_structures/src/owning_ref/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// FIXME: owning_ref is not sound under stacked borrows. Preferably, get rid of it.
2+
#[cfg(not(miri))]
13
mod owning_ref {
24
use super::super::OwningRef;
35
use super::super::{BoxRef, Erased, ErasedBoxRef, RcRef};
@@ -361,6 +363,8 @@ mod owning_handle {
361363
}
362364
}
363365

366+
// FIXME: owning_ref is not sound under stacked borrows. Preferably, get rid of it.
367+
#[cfg(not(miri))]
364368
mod owning_ref_mut {
365369
use super::super::BoxRef;
366370
use super::super::{BoxRefMut, Erased, ErasedBoxRefMut, OwningRefMut};

compiler/rustc_data_structures/src/sip128.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ impl SipHasher128 {
255255
// elements from spill (at most LEN - 1 bytes could have overflowed
256256
// into the spill). The memcpy call is optimized away because the size
257257
// is known. And the whole copy is optimized away for LEN == 1.
258+
let dst = self.buf.as_mut_ptr() as *mut u8;
258259
let src = self.buf.get_unchecked(BUFFER_SPILL_INDEX) as *const _ as *const u8;
259-
ptr::copy_nonoverlapping(src, self.buf.as_mut_ptr() as *mut u8, LEN - 1);
260+
ptr::copy_nonoverlapping(src, dst, LEN - 1);
260261

261262
// This function should only be called when the write fills the buffer.
262263
// Therefore, when LEN == 1, the new `self.nbuf` must be zero.

0 commit comments

Comments
 (0)