Allow switching on non-integer types.
This commit is contained in:
parent
96c51dc8ed
commit
cc8b8efd33
3 changed files with 13 additions and 14 deletions
|
@ -158,16 +158,15 @@ impl<'a, 'tcx: 'a> Interpreter<'a, 'tcx> {
|
|||
}
|
||||
|
||||
SwitchInt { ref discr, ref values, ref targets, .. } => {
|
||||
// FIXME(tsion): Handle non-integer switch types.
|
||||
let (discr_ptr, discr_repr) = try!(self.eval_lvalue(discr));
|
||||
let discr_val = try!(self.memory.read_i64(discr_ptr));
|
||||
let discr_val = try!(self.memory.read_primval(discr_ptr, &discr_repr));
|
||||
|
||||
// Branch to the `otherwise` case by default, if no match is found.
|
||||
current_block = targets[targets.len() - 1];
|
||||
|
||||
for (index, val_const) in values.iter().enumerate() {
|
||||
let ptr = try!(self.const_to_ptr(val_const));
|
||||
let val = try!(self.memory.read_i64(ptr));
|
||||
let val = try!(self.memory.read_primval(ptr, &discr_repr));
|
||||
if discr_val == val {
|
||||
current_block = targets[index];
|
||||
break;
|
||||
|
|
|
@ -16,11 +16,11 @@ fn if_true() -> i64 {
|
|||
if true { 1 } else { 0 }
|
||||
}
|
||||
|
||||
// #[miri_run]
|
||||
// fn match_bool() -> i64 {
|
||||
// let b = true;
|
||||
// match b {
|
||||
// true => 1,
|
||||
// false => 0,
|
||||
// }
|
||||
// }
|
||||
#[miri_run]
|
||||
fn match_bool() -> i16 {
|
||||
let b = true;
|
||||
match b {
|
||||
true => 1,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,13 +24,13 @@ fn indirect_add() -> i64 {
|
|||
}
|
||||
|
||||
#[miri_run]
|
||||
fn arith() -> i64 {
|
||||
fn arith() -> i32 {
|
||||
3*3 + 4*4
|
||||
}
|
||||
|
||||
#[miri_run]
|
||||
fn match_int() -> i64 {
|
||||
let n = 2i64;
|
||||
fn match_int() -> i16 {
|
||||
let n = 2;
|
||||
match n {
|
||||
0 => 0,
|
||||
1 => 10,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue