Skip to content

Commit

Permalink
Merge pull request #36 from alexcrichton/stack-borrows
Browse files Browse the repository at this point in the history
Get Stack Borrows mostly working
  • Loading branch information
alexcrichton authored Jan 28, 2024
2 parents 5942886 + 6f4c044 commit 621d530
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ jobs:
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- name: Test with Miri
- name: Test with Miri Stack Borrows
run: cargo miri test
- name: Test with Miri Tree Borrows
run: cargo miri test
env:
MIRIFLAGS: -Zmiri-tree-borrows
8 changes: 5 additions & 3 deletions src/dlmalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,11 @@ impl<A: Allocator> Dlmalloc<A> {
(*chunk).child[1] = ptr::null_mut();
let chunkc = TreeChunk::chunk(chunk);
if !self.treemap_is_marked(idx) {
self.mark_treemap(idx);
*h = chunk;
(*chunk).parent = h.cast(); // TODO: dubious?
(*chunkc).next = chunkc;
(*chunkc).prev = chunkc;
self.mark_treemap(idx);
} else {
let mut t = *h;
let mut k = size << leftshift_for_tree_index(idx);
Expand Down Expand Up @@ -1519,8 +1519,7 @@ impl<A: Allocator> Dlmalloc<A> {
if !cfg!(debug_assertions) {
return;
}
let tb = self.treebin_at(idx);
let t = *tb;
let t = *self.treebin_at(idx);
let empty = self.treemap & (1 << idx) == 0;
if t.is_null() {
debug_assert!(empty);
Expand Down Expand Up @@ -1563,6 +1562,9 @@ impl<A: Allocator> Dlmalloc<A> {
debug_assert!(head.is_null());
head = u;
debug_assert!((*u).parent != u);
// TODO: unsure why this triggers UB in stacked borrows in MIRI
// (works in tree borrows though)
#[cfg(not(miri))]
debug_assert!(
(*(*u).parent).child[0] == u
|| (*(*u).parent).child[1] == u
Expand Down

0 comments on commit 621d530

Please sign in to comment.