miri: Rename to_{u,i}size to to_machine_{u,i}size
Having a function `to_usize` that does not return a usize is somewhat confusing
This commit is contained in:
parent
c34472b770
commit
900fc9a2f0
8 changed files with 14 additions and 14 deletions
|
|
@ -439,7 +439,7 @@ impl<'tcx, Tag> Scalar<Tag> {
|
|||
Ok(b as u64)
|
||||
}
|
||||
|
||||
pub fn to_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> {
|
||||
pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> {
|
||||
let b = self.to_bits(cx.data_layout().pointer_size)?;
|
||||
Ok(b as u64)
|
||||
}
|
||||
|
|
@ -465,7 +465,7 @@ impl<'tcx, Tag> Scalar<Tag> {
|
|||
Ok(b as i64)
|
||||
}
|
||||
|
||||
pub fn to_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> {
|
||||
pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> {
|
||||
let sz = cx.data_layout().pointer_size;
|
||||
let b = self.to_bits(sz)?;
|
||||
let b = sign_extend(b, sz) as i128;
|
||||
|
|
@ -592,8 +592,8 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
|
||||
self.not_undef()?.to_usize(cx)
|
||||
pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
|
||||
self.not_undef()?.to_machine_usize(cx)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -612,8 +612,8 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
|
||||
self.not_undef()?.to_isize(cx)
|
||||
pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
|
||||
self.not_undef()?.to_machine_isize(cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ fn op_to_const<'tcx>(
|
|||
0,
|
||||
),
|
||||
};
|
||||
let len = b.to_usize(&ecx.tcx.tcx).unwrap();
|
||||
let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
|
||||
let start = start.try_into().unwrap();
|
||||
let len: usize = len.try_into().unwrap();
|
||||
ConstValue::Slice {
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
|
||||
ty::Slice(_) | ty::Str => {
|
||||
let len = metadata.expect("slice fat ptr must have vtable").to_usize(self)?;
|
||||
let len = metadata.expect("slice fat ptr must have length").to_machine_usize(self)?;
|
||||
let elem = layout.field(self, 0)?;
|
||||
|
||||
// Make sure the slice is not too big.
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ for
|
|||
ty::Array(_, n)
|
||||
if n.eval_usize(self.ecx.tcx.tcx, self.ecx.param_env) == 0 => {}
|
||||
ty::Slice(_)
|
||||
if mplace.meta.unwrap().to_usize(self.ecx)? == 0 => {}
|
||||
if mplace.meta.unwrap().to_machine_usize(self.ecx)? == 0 => {}
|
||||
_ => bug!("const qualif failed to prevent mutable references"),
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -263,8 +263,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// This is the dual to the special exception for offset-by-0
|
||||
// in the inbounds pointer offset operation (see the Miri code, `src/operator.rs`).
|
||||
if a.is_bits() && b.is_bits() {
|
||||
let a = a.to_usize(self)?;
|
||||
let b = b.to_usize(self)?;
|
||||
let a = a.to_machine_usize(self)?;
|
||||
let b = b.to_machine_usize(self)?;
|
||||
if a == b && a != 0 {
|
||||
self.write_scalar(Scalar::from_int(0, isize_layout.size), dest)?;
|
||||
return Ok(true);
|
||||
|
|
|
|||
|
|
@ -915,7 +915,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
|
||||
match scalar {
|
||||
Scalar::Ptr(ptr) => Ok(ptr),
|
||||
_ => M::int_to_ptr(&self, scalar.to_usize(self)?)
|
||||
_ => M::int_to_ptr(&self, scalar.to_machine_usize(self)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
|
|||
// We need to consult `meta` metadata
|
||||
match self.layout.ty.kind {
|
||||
ty::Slice(..) | ty::Str =>
|
||||
return self.mplace.meta.unwrap().to_usize(cx),
|
||||
return self.mplace.meta.unwrap().to_machine_usize(cx),
|
||||
_ => bug!("len not supported on unsized type {:?}", self.layout.ty),
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
|
|||
// FIXME: More checks for the vtable.
|
||||
}
|
||||
ty::Slice(..) | ty::Str => {
|
||||
let _len = try_validation!(meta.unwrap().to_usize(self.ecx),
|
||||
let _len = try_validation!(meta.unwrap().to_machine_usize(self.ecx),
|
||||
"non-integer slice length in wide pointer", self.path);
|
||||
// We do not check that `len * elem_size <= isize::MAX`:
|
||||
// that is only required for references, and there it falls out of the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue