提交 2a5029ed 编写于 作者: S Scott Olson

Update MIR passes to match rustc.

上级 b233ada5
......@@ -465,7 +465,7 @@ pub(super) fn eval_rvalue_into_lvalue(
let operand_ty = self.operand_ty(operand);
assert_eq!(self.type_size(operand_ty)?, Some(0));
}
self.write_primval(dest, PrimVal::from_i64(0), dest_ty)?;
self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?;
}
} else {
bug!("tried to assign {:?} to Layout::RawNullablePointer", kind);
......@@ -1423,11 +1423,21 @@ pub fn run_mir_passes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
passes.push_pass(Box::new(::rustc_mir::transform::no_landing_pads::NoLandingPads));
passes.push_pass(Box::new(::rustc_mir::transform::simplify::SimplifyCfg::new("no-landing-pads")));
// From here on out, regions are gone.
passes.push_pass(Box::new(::rustc_mir::transform::erase_regions::EraseRegions));
passes.push_pass(Box::new(::rustc_mir::transform::add_call_guards::AddCallGuards));
passes.push_pass(Box::new(::rustc_borrowck::ElaborateDrops));
passes.push_pass(Box::new(::rustc_mir::transform::no_landing_pads::NoLandingPads));
passes.push_pass(Box::new(::rustc_mir::transform::simplify::SimplifyCfg::new("elaborate-drops")));
// No lifetime analysis based on borrowing can be done from here on out.
passes.push_pass(Box::new(::rustc_mir::transform::instcombine::InstCombine::new()));
passes.push_pass(Box::new(::rustc_mir::transform::deaggregator::Deaggregator));
passes.push_pass(Box::new(::rustc_mir::transform::copy_prop::CopyPropagation));
passes.push_pass(Box::new(::rustc_mir::transform::simplify::SimplifyLocals));
passes.push_pass(Box::new(::rustc_mir::transform::add_call_guards::AddCallGuards));
passes.push_pass(Box::new(::rustc_mir::transform::dump_mir::Marker("PreMiri")));
passes.run_passes(tcx);
......
use rustc::hir::def_id::DefId;
use rustc::mir;
use rustc::ty::layout::Size;
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
use rustc_data_structures::indexed_vec::Idx;
......@@ -196,7 +197,7 @@ fn eval_lvalue_projection(
}
RawNullablePointer { .. } => {
assert_eq!(field.index(), 0);
assert_eq!(field, 0);
return Ok(base);
}
......@@ -206,6 +207,13 @@ fn eval_lvalue_projection(
UntaggedUnion { .. } => return Ok(base),
Vector { element, count } => {
let field = field as u64;
assert!(field < count);
let elem_size = element.size(&self.tcx.data_layout).bytes();
Size::from_bytes(field * elem_size)
}
_ => bug!("field access on non-product type: {:?}", base_layout),
};
......
......@@ -8,6 +8,7 @@
use rustc::hir;
use rustc::mir::visit::{Visitor, LvalueContext};
use rustc::mir;
use rustc::ty::layout::Layout;
use rustc::ty::{subst, self};
use error::{EvalResult, EvalError};
......@@ -85,7 +86,34 @@ fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx, ()> {
use rustc::mir::StatementKind::*;
match stmt.kind {
Assign(ref lvalue, ref rvalue) => self.eval_rvalue_into_lvalue(rvalue, lvalue)?,
SetDiscriminant { .. } => unimplemented!(),
SetDiscriminant { ref lvalue, variant_index } => {
let dest = self.eval_lvalue(lvalue)?;
let dest_ty = self.lvalue_ty(lvalue);
let dest_layout = self.type_layout(dest_ty)?;
match *dest_layout {
Layout::General { discr, ref variants, .. } => {
let discr_size = discr.size().bytes();
let discr_offset = variants[variant_index].offsets[0].bytes();
// FIXME(solson)
let dest = self.force_allocation(dest)?;
let discr_dest = (dest.to_ptr()).offset(discr_offset);
self.memory.write_uint(discr_dest, variant_index as u64, discr_size)?;
}
Layout::RawNullablePointer { nndiscr, .. } => {
use value::PrimVal;
if variant_index as u64 != nndiscr {
self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?;
}
}
_ => bug!("SetDiscriminant on {} represented as {:#?}", dest_ty, dest_layout),
}
}
// Miri can safely ignore these. Only translation needs it.
StorageLive(_) |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册