stronger consistency check in ImmTy::from_immediate

This commit is contained in:
Ralf Jung 2023-09-20 22:28:46 +02:00
parent bdbf545f42
commit 23fd2860fa

View File

@ -159,7 +159,15 @@ pub fn from_scalar(val: Scalar<Prov>, layout: TyAndLayout<'tcx>) -> Self {
#[inline(always)] #[inline(always)]
pub fn from_immediate(imm: Immediate<Prov>, layout: TyAndLayout<'tcx>) -> Self { pub fn from_immediate(imm: Immediate<Prov>, layout: TyAndLayout<'tcx>) -> Self {
debug_assert!(layout.is_sized(), "immediates must be sized"); debug_assert!(
match (imm, layout.abi) {
(Immediate::Scalar(..), Abi::Scalar(..)) => true,
(Immediate::ScalarPair(..), Abi::ScalarPair(..)) => true,
(Immediate::Uninit, _) if layout.is_sized() => true,
_ => false,
},
"immediate {imm:?} does not fit to layout {layout:?}",
);
ImmTy { imm, layout } ImmTy { imm, layout }
} }
@ -448,7 +456,7 @@ fn read_immediate_from_mplace_raw(
alloc_range(Size::ZERO, size), alloc_range(Size::ZERO, size),
/*read_provenance*/ matches!(s, abi::Pointer(_)), /*read_provenance*/ matches!(s, abi::Pointer(_)),
)?; )?;
Some(ImmTy { imm: scalar.into(), layout: mplace.layout }) Some(ImmTy::from_scalar(scalar, mplace.layout))
} }
Abi::ScalarPair( Abi::ScalarPair(
abi::Scalar::Initialized { value: a, .. }, abi::Scalar::Initialized { value: a, .. },
@ -468,7 +476,7 @@ fn read_immediate_from_mplace_raw(
alloc_range(b_offset, b_size), alloc_range(b_offset, b_size),
/*read_provenance*/ matches!(b, abi::Pointer(_)), /*read_provenance*/ matches!(b, abi::Pointer(_)),
)?; )?;
Some(ImmTy { imm: Immediate::ScalarPair(a_val, b_val), layout: mplace.layout }) Some(ImmTy::from_immediate(Immediate::ScalarPair(a_val, b_val), mplace.layout))
} }
_ => { _ => {
// Neither a scalar nor scalar pair. // Neither a scalar nor scalar pair.