From 586bc5d1da55e776b39601ad06f00c7cae0a0f5e Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Mon, 7 Mar 2016 04:48:12 -0600 Subject: [PATCH] Reimplement 'if' conditions. --- src/interpreter.rs | 16 +++++++--------- test/new_values.rs | 16 ++++++++-------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 3abc4231edd7..6e01f8e7944f 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -162,8 +162,15 @@ impl<'a, 'tcx> Interpreter<'a, 'tcx> { use rustc::mir::repr::Terminator::*; match *block_data.terminator() { Return => break, + Goto { target } => block = target, + If { ref cond, targets: (then_target, else_target) } => { + let cond_ptr = try!(self.operand_to_ptr(cond)); + let cond = try!(self.memory.read_bool(&cond_ptr)); + block = if cond { then_target } else { else_target } + } + // Call { ref func, ref args, ref destination, .. } => { // let ptr = destination.as_ref().map(|&(ref lv, _)| self.lvalue_to_ptr(lv)); // let func_val = self.operand_to_ptr(func); @@ -192,15 +199,6 @@ impl<'a, 'tcx> Interpreter<'a, 'tcx> { // } // } - // If { ref cond, targets: (then_target, else_target) } => { - // let cond_ptr = try!(self.operand_to_ptr(cond)); - // match self.operand_to_ptr(cond) { - // Value::Bool(true) => block = then_target, - // Value::Bool(false) => block = else_target, - // cond_val => panic!("Non-boolean `if` condition value: {:?}", cond_val), - // } - // } - // SwitchInt { ref discr, ref values, ref targets, .. } => { // let discr_val = self.read_lvalue(discr); diff --git a/test/new_values.rs b/test/new_values.rs index b4a506a9fb46..880ac71abc30 100644 --- a/test/new_values.rs +++ b/test/new_values.rs @@ -51,15 +51,15 @@ fn boolean() -> bool { true } -// #[miri_run(expected = "Int(0)")] -// fn if_false() -> i32 { -// if false { 1 } else { 0 } -// } +#[miri_run] +fn if_false() -> i32 { + if false { 1 } else { 0 } +} -// #[miri_run(expected = "Int(1)")] -// fn if_true() -> i32 { -// if true { 1 } else { 0 } -// } +#[miri_run] +fn if_true() -> i32 { + if true { 1 } else { 0 } +} // #[miri_run(expected = "Int(2)")] // fn call() -> i32 {