Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve soundness of rustc_data_structures #97707

Merged
merged 2 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_data_structures/src/base_n/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ fn test_encode() {
test(u64::MAX as u128, base);
test(u128::MAX, base);

for i in 0..1_000 {
const N: u128 = if cfg!(miri) { 10 } else { 1000 };

for i in 0..N {
test(i * 983, base);
}
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_data_structures/src/graph/scc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ fn test_deep_linear() {
v
*/
#[cfg(not(miri))]
const NR_NODES: usize = 1 << 14;
#[cfg(miri)]
const NR_NODES: usize = 1 << 3;
let mut nodes = vec![];
for i in 1..NR_NODES {
nodes.push((i - 1, i));
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_data_structures/src/owning_ref/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FIXME: owning_ref is not sound under stacked borrows. Preferably, get rid of it.
#[cfg(not(miri))]
mod owning_ref {
use super::super::OwningRef;
use super::super::{BoxRef, Erased, ErasedBoxRef, RcRef};
Expand Down Expand Up @@ -361,6 +363,8 @@ mod owning_handle {
}
}

// FIXME: owning_ref is not sound under stacked borrows. Preferably, get rid of it.
#[cfg(not(miri))]
mod owning_ref_mut {
use super::super::BoxRef;
use super::super::{BoxRefMut, Erased, ErasedBoxRefMut, OwningRefMut};
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_data_structures/src/sip128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ impl SipHasher128 {
// elements from spill (at most LEN - 1 bytes could have overflowed
// into the spill). The memcpy call is optimized away because the size
// is known. And the whole copy is optimized away for LEN == 1.
let dst = self.buf.as_mut_ptr() as *mut u8;
let src = self.buf.get_unchecked(BUFFER_SPILL_INDEX) as *const _ as *const u8;
ptr::copy_nonoverlapping(src, self.buf.as_mut_ptr() as *mut u8, LEN - 1);
ptr::copy_nonoverlapping(src, dst, LEN - 1);

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