提交 a6b9b165 编写于 作者: S Scott Olson

Handle CEnum layouts with signed representations.

上级 5f07e2eb
......@@ -688,14 +688,15 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
}
}
CEnum { discr, signed, min, max } => {
CEnum { discr, signed, .. } => {
assert_eq!(operands.len(), 0);
if let mir::AggregateKind::Adt(adt_def, variant, _) = *kind {
let val = adt_def.variants[variant].disr_val.to_u64_unchecked();
let size = discr.size().bytes() as usize;
if signed {
unimplemented!()
try!(self.memory.write_int(dest, val as i64, size));
} else {
let val = adt_def.variants[variant].disr_val.to_u64().unwrap();
let size = discr.size().bytes() as usize;
try!(self.memory.write_uint(dest, val, size));
}
} else {
......
......@@ -7,11 +7,22 @@ enum Foo {
Quux = 100,
}
enum Signed {
Bar = -42,
Baz,
Quux = 100,
}
#[miri_run]
fn foo() -> [u8; 3] {
[Foo::Bar as u8, Foo::Baz as u8, Foo::Quux as u8]
}
#[miri_run]
fn signed() -> [i8; 3] {
[Signed::Bar as i8, Signed::Baz as i8, Signed::Quux as i8]
}
#[miri_run]
fn unsafe_match() -> bool {
match unsafe { std::mem::transmute::<u8, Foo>(43) } {
......@@ -22,5 +33,7 @@ fn unsafe_match() -> bool {
#[miri_run]
fn main() {
// assert_eq!(foo(), [42, 43, 100]);
// assert_eq!(signed(), [-42, -41, 100]);
assert!(unsafe_match());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册