Auto merge of #2279 - RalfJung:adjacent-allocs, r=RalfJung

Allow non-ZST allocations to be adjacent

Also `cargo update` in test-cargo-miri... no need to make a separate PR for that right?...
This commit is contained in:
bors 2022-06-28 02:52:23 +00:00
commit aaaed51ab8
6 changed files with 106 additions and 51 deletions

View file

@ -1,4 +1,5 @@
use std::cell::RefCell;
use std::cmp::max;
use std::collections::hash_map::Entry;
use log::trace;
@ -187,11 +188,11 @@ impl<'mir, 'tcx> GlobalStateInner {
slack,
);
// Remember next base address. Leave a gap of at least 1 to avoid two zero-sized allocations
// having the same base address, and to avoid ambiguous provenance for the address between two
// allocations (also see https://github.com/rust-lang/unsafe-code-guidelines/issues/313).
let size_plus_1 = size.bytes().checked_add(1).unwrap();
global_state.next_base_addr = base_addr.checked_add(size_plus_1).unwrap();
// Remember next base address. If this allocation is zero-sized, leave a gap
// of at least 1 to avoid two allocations having the same base address.
// (The logic in `alloc_id_from_addr` assumes unique addresses, and function
// pointers to different functions need to be distinguishable!)
global_state.next_base_addr = base_addr.checked_add(max(size.bytes(), 1)).unwrap();
// Given that `next_base_addr` increases in each allocation, pushing the
// corresponding tuple keeps `int_to_ptr_map` sorted
global_state.int_to_ptr_map.push((base_addr, alloc_id));