Skip to content

Commit 23fd286

Browse files
committed
stronger consistency check in ImmTy::from_immediate
1 parent bdbf545 commit 23fd286

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,15 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
159159

160160
#[inline(always)]
161161
pub fn from_immediate(imm: Immediate<Prov>, layout: TyAndLayout<'tcx>) -> Self {
162-
debug_assert!(layout.is_sized(), "immediates must be sized");
162+
debug_assert!(
163+
match (imm, layout.abi) {
164+
(Immediate::Scalar(..), Abi::Scalar(..)) => true,
165+
(Immediate::ScalarPair(..), Abi::ScalarPair(..)) => true,
166+
(Immediate::Uninit, _) if layout.is_sized() => true,
167+
_ => false,
168+
},
169+
"immediate {imm:?} does not fit to layout {layout:?}",
170+
);
163171
ImmTy { imm, layout }
164172
}
165173

@@ -448,7 +456,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
448456
alloc_range(Size::ZERO, size),
449457
/*read_provenance*/ matches!(s, abi::Pointer(_)),
450458
)?;
451-
Some(ImmTy { imm: scalar.into(), layout: mplace.layout })
459+
Some(ImmTy::from_scalar(scalar, mplace.layout))
452460
}
453461
Abi::ScalarPair(
454462
abi::Scalar::Initialized { value: a, .. },
@@ -468,7 +476,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
468476
alloc_range(b_offset, b_size),
469477
/*read_provenance*/ matches!(b, abi::Pointer(_)),
470478
)?;
471-
Some(ImmTy { imm: Immediate::ScalarPair(a_val, b_val), layout: mplace.layout })
479+
Some(ImmTy::from_immediate(Immediate::ScalarPair(a_val, b_val), mplace.layout))
472480
}
473481
_ => {
474482
// Neither a scalar nor scalar pair.

0 commit comments

Comments
 (0)