Skip to content

Commit aed1e7a

Browse files
committed
Remove all uses of to_ptr
1 parent 048af40 commit aed1e7a

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

src/shims/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn alloc_env_var<'mir, 'tcx>(
4444
bytes.push(b'=');
4545
bytes.extend_from_slice(value);
4646
bytes.push(0);
47-
memory.allocate_static_bytes(bytes.as_slice(), MiriMemoryKind::Env.into())
47+
memory.allocate_static_bytes(bytes.as_slice(), MiriMemoryKind::Env.into()).assert_ptr()
4848
}
4949

5050
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}

src/shims/foreign_items.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8181
if new_size == 0 {
8282
Ok(Scalar::from_int(0, this.pointer_size()))
8383
} else {
84-
let new_ptr =
85-
this.memory
86-
.allocate(Size::from_bytes(new_size), new_align, kind.into());
87-
Ok(Scalar::Ptr(new_ptr))
84+
Ok(this.memory.allocate(Size::from_bytes(new_size), new_align, kind.into()))
8885
}
8986
} else {
9087
let old_ptr = this.force_ptr(old_ptr)?;
9188
if new_size == 0 {
9289
this.memory.deallocate(old_ptr, None, kind.into())?;
9390
Ok(Scalar::from_int(0, this.pointer_size()))
9491
} else {
95-
let new_ptr = this.memory.reallocate(
92+
this.memory.reallocate(
9693
old_ptr,
9794
None,
9895
Size::from_bytes(new_size),
9996
new_align,
10097
kind.into(),
101-
)?;
102-
Ok(Scalar::Ptr(new_ptr))
98+
)
10399
}
104100
}
105101
}
@@ -276,7 +272,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
276272
)?;
277273
}
278274
"__rust_realloc" => {
279-
let ptr = this.read_scalar(args[0])?.to_ptr()?;
275+
let ptr = match this.read_scalar(args[0])?.not_undef()? {
276+
Scalar::Ptr(p) => p,
277+
Scalar::Raw { .. } => throw_ub_format!("cannot reallocate integer addresses"),
278+
};
280279
let old_size = this.read_scalar(args[1])?.to_machine_usize(this)?;
281280
let align = this.read_scalar(args[2])?.to_machine_usize(this)?;
282281
let new_size = this.read_scalar(args[3])?.to_machine_usize(this)?;

src/shims/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
553553
// Do it in memory
554554
let mplace = this.force_allocation(dest)?;
555555
mplace.meta.unwrap_none();
556-
let ptr = mplace.ptr.to_ptr()?;
556+
let ptr = mplace.ptr.assert_ptr();
557557
// We know the return place is in-bounds
558558
this.memory
559559
.get_raw_mut(ptr.alloc_id)?

src/stacked_borrows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
538538
) -> InterpResult<'tcx> {
539539
let this = self.eval_context_mut();
540540
let protector = if protect { Some(this.frame().extra.call_id) } else { None };
541-
let ptr = place.ptr.to_ptr().expect("we should have a proper pointer");
541+
let ptr = place.ptr.assert_ptr();
542542
trace!("reborrow: {} reference {:?} derived from {:?} (pointee {}): {:?}, size {}",
543543
kind, new_tag, ptr.tag, place.layout.ty, ptr.erase_tag(), size.bytes());
544544

0 commit comments

Comments
 (0)