Read discriminant as a signed integer if specified by layout.

This ensures it gets sign extended correctly.

Fixes #78
This commit is contained in:
Paul Lietar 2016-11-05 02:53:02 +00:00
parent ce8806d141
commit 86062ef930
2 changed files with 19 additions and 1 deletions

View File

@ -252,11 +252,16 @@ fn read_discriminant_value(&self, adt_ptr: Pointer, adt_ty: Ty<'tcx>) -> EvalRes
let adt_layout = self.type_layout(adt_ty);
let discr_val = match *adt_layout {
General { discr, .. } | CEnum { discr, .. } => {
General { discr, .. } | CEnum { discr, signed: false, .. } => {
let discr_size = discr.size().bytes();
self.memory.read_uint(adt_ptr, discr_size as usize)?
}
CEnum { discr, signed: true, .. } => {
let discr_size = discr.size().bytes();
self.memory.read_int(adt_ptr, discr_size as usize)? as u64
}
RawNullablePointer { nndiscr, .. } => {
self.read_nonnull_discriminant_value(adt_ptr, nndiscr)?
}

View File

@ -0,0 +1,13 @@
enum AB { A = -1, B = 1 }
fn main() {
match AB::A {
AB::A => (),
AB::B => panic!(),
}
match AB::B {
AB::A => panic!(),
AB::B => (),
}
}