Fix print_miri_value for signed integers
This commit is contained in:
parent
97a032ebb4
commit
be12b242ce
@ -35,6 +35,7 @@ use std::slice;
|
||||
use std::vec::IntoIter;
|
||||
use std::{iter, mem, option, u32};
|
||||
use syntax::ast::{self, Name};
|
||||
use syntax::attr::SignedInt;
|
||||
use syntax::symbol::InternedString;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
@ -2228,7 +2229,7 @@ pub fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ty::Const) -> fmt::Resul
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Result {
|
||||
pub fn print_miri_value<'tcx, W: Write>(value: Value, ty: Ty<'tcx>, f: &mut W) -> fmt::Result {
|
||||
use ty::TypeVariants::*;
|
||||
// print some primitives
|
||||
if let Value::Scalar(ScalarMaybeUndef::Scalar(Scalar::Bits { bits, .. })) = value {
|
||||
|
@ -668,19 +668,14 @@ impl<'tcx> IntRange<'tcx> {
|
||||
ty::TyInt(_) => {
|
||||
// FIXME(49937): refactor these bit manipulations into interpret.
|
||||
let bits = tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
|
||||
.unwrap().size.bits() as u128;
|
||||
.unwrap().size.bits() as u128;
|
||||
let min = 1u128 << (bits - 1);
|
||||
let mask = !0u128 >> (128 - bits);
|
||||
if encode {
|
||||
let offset = |x: u128| x.wrapping_sub(min) & mask;
|
||||
(offset(lo), offset(hi))
|
||||
} else {
|
||||
let offset = |x: u128| {
|
||||
// FIXME: this shouldn't be necessary once `print_miri_value`
|
||||
// sign-extends `TyInt`.
|
||||
interpret::sign_extend(tcx, x.wrapping_add(min) & mask, ty)
|
||||
.expect("layout error for TyInt")
|
||||
};
|
||||
let offset = |x: u128| x.wrapping_add(min) & mask;
|
||||
(offset(lo), offset(hi))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user