1
Fork 0

ScalarInt: add methods to assert being a (u)int of given size

This commit is contained in:
Ralf Jung 2024-04-18 08:38:37 +02:00
parent 5e6184cdb7
commit 42220f0930
13 changed files with 78 additions and 72 deletions

View file

@ -295,8 +295,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
&niche_start_val,
)?
.to_scalar()
.try_to_int()
.unwrap();
.assert_int();
Ok(Some((tag, tag_field)))
}
}

View file

@ -249,7 +249,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
}
/// Return the immediate as a `ScalarInt`. Ensures that it has the size that the layout of the
/// immediate indcates.
/// immediate indicates.
#[inline]
pub fn to_scalar_int(&self) -> InterpResult<'tcx, ScalarInt> {
let s = self.to_scalar().to_scalar_int()?;

View file

@ -155,10 +155,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let l = left.to_scalar_int()?;
let r = right.to_scalar_int()?;
// Prepare to convert the values to signed or unsigned form.
let l_signed = || l.try_to_int(left.layout.size).unwrap();
let l_unsigned = || l.try_to_uint(left.layout.size).unwrap();
let r_signed = || r.try_to_int(right.layout.size).unwrap();
let r_unsigned = || r.try_to_uint(right.layout.size).unwrap();
let l_signed = || l.assert_int(left.layout.size);
let l_unsigned = || l.assert_uint(left.layout.size);
let r_signed = || r.assert_int(right.layout.size);
let r_unsigned = || r.assert_uint(right.layout.size);
let throw_ub_on_overflow = match bin_op {
AddUnchecked => Some(sym::unchecked_add),