Do not force_allocate SwitchInt discrs.

This commit is contained in:
Scott Olson 2016-10-15 23:59:01 -06:00
parent 49e6c57ef9
commit 754dcc401d
2 changed files with 14 additions and 17 deletions

View File

@ -791,17 +791,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<'tcx, Value> {
use rustc::mir::repr::Operand::*;
match *op {
Consume(ref lvalue) => {
match self.eval_lvalue(lvalue)? {
Lvalue::Ptr { ptr, extra } => {
assert_eq!(extra, LvalueExtra::None);
Ok(Value::ByRef(ptr))
}
Lvalue::Local { frame, local } => {
self.stack[frame].get_local(local).ok_or(EvalError::ReadUndefBytes)
}
}
}
Consume(ref lvalue) => self.eval_and_read_lvalue(lvalue),
Constant(mir::Constant { ref literal, ty, .. }) => {
use rustc::mir::repr::Literal;
@ -841,6 +831,18 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
}
fn eval_and_read_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Value> {
match self.eval_lvalue(lvalue)? {
Lvalue::Ptr { ptr, extra } => {
assert_eq!(extra, LvalueExtra::None);
Ok(Value::ByRef(ptr))
}
Lvalue::Local { frame, local } => {
self.stack[frame].get_local(local).ok_or(EvalError::ReadUndefBytes)
}
}
}
fn eval_lvalue(&mut self, mir_lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue> {
use rustc::mir::repr::Lvalue::*;
let lvalue = match *mir_lvalue {

View File

@ -41,13 +41,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
SwitchInt { ref discr, ref values, ref targets, .. } => {
// FIXME(solson)
let lvalue = self.eval_lvalue(discr)?;
let lvalue = self.force_allocation(lvalue)?;
let discr_ptr = lvalue.to_ptr();
let discr_val = self.eval_and_read_lvalue(discr)?;
let discr_ty = self.lvalue_ty(discr);
let discr_val = self.read_value(discr_ptr, discr_ty)?;
let discr_prim = self.value_to_primval(discr_val, discr_ty)?;
// Branch to the `otherwise` case by default, if no match is found.