Skip to content

Commit 2807f4f

Browse files
oli-obknox
authored andcommitted
Properly evaluate zst enum
1 parent 1839ec5 commit 2807f4f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustc_mir/interpret/eval_context.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,15 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
13191319
pub fn try_read_value(&self, ptr: Pointer, ptr_align: Align, ty: Ty<'tcx>) -> EvalResult<'tcx, Option<Value>> {
13201320
use syntax::ast::FloatTy;
13211321

1322+
let layout = self.layout_of(ty)?;
1323+
// do the strongest layout check of the two
1324+
let align = layout.align.max(ptr_align);
1325+
self.memory.check_align(ptr, align)?;
1326+
1327+
if layout.size.bytes() == 0 {
1328+
return Ok(Some(Value::ByVal(PrimVal::Undef)));
1329+
}
1330+
13221331
let ptr = ptr.to_ptr()?;
13231332
let val = match ty.sty {
13241333
ty::TyBool => {

src/librustc_mir/interpret/place.rs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
136136
let val = [a, b][field_index];
137137
Ok(Some((Value::ByVal(val), field.ty)))
138138
},
139+
// FIXME(oli-obk): figure out whether we should be calling `try_read_value` here
139140
_ => Ok(None),
140141
}
141142
}

0 commit comments

Comments
 (0)