Skip to content

Commit 116dba4

Browse files
committed
review: factor out .expose_provenance().try_into().unwrap()
1 parent 16876c4 commit 116dba4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/tools/miri/src/alloc_addresses/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,21 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
176176
let base_addr = if ecx.machine.native_lib.is_some() {
177177
match kind {
178178
AllocKind::LiveData => {
179-
if ecx.tcx.try_get_global_alloc(alloc_id).is_some() {
179+
let ptr = if ecx.tcx.try_get_global_alloc(alloc_id).is_some() {
180180
// For new global allocations, we always pre-allocate the memory to be able use the machine address directly.
181181
let prepared_bytes = MiriAllocBytes::zeroed(size, align)
182182
.unwrap_or_else(|| {
183183
panic!("Miri ran out of memory: cannot create allocation of {size:?} bytes")
184184
});
185-
let addr = prepared_bytes.as_ptr().addr().try_into().unwrap();
186-
// Store prepared allocation space to be picked up for use later.
187-
global_state.prepared_alloc_bytes.try_insert(alloc_id, prepared_bytes).unwrap();
188-
addr
185+
let ptr = prepared_bytes.as_ptr();
186+
// Store prepared allocation space to be picked up for use later.
187+
global_state.prepared_alloc_bytes.try_insert(alloc_id, prepared_bytes).unwrap();
188+
ptr
189189
} else {
190-
ecx.get_alloc_bytes_unchecked_raw(alloc_id)?.addr().try_into().unwrap()
191-
}
190+
ecx.get_alloc_bytes_unchecked_raw(alloc_id)?
191+
};
192+
// Ensure this pointer's provenance is exposed, so that it can be used by FFI code.
193+
ptr.expose_provenance().try_into().unwrap()
192194
}
193195
AllocKind::Function | AllocKind::VTable => {
194196
// Allocate some dummy memory to get a unique address for this function/vtable.

src/tools/miri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(trait_upcasting)]
1414
#![feature(strict_overflow_ops)]
1515
#![feature(strict_provenance)]
16+
#![feature(exposed_provenance)]
1617
// Configure clippy and other lints
1718
#![allow(
1819
clippy::collapsible_else_if,

0 commit comments

Comments
 (0)