Implement Rvalue::Len for arrays

This commit is contained in:
bjorn3 2018-10-06 13:50:31 +02:00
parent 2cf7a64021
commit f4e544894a
3 changed files with 15 additions and 6 deletions

View file

@ -168,4 +168,6 @@ fn main() {
Ordering::Less => {},
_ => assert!(false),
}
[NoisyDropInner, NoisyDropInner];
}

View file

@ -589,12 +589,19 @@ fn trans_stmt<'a, 'tcx: 'a>(
}
Rvalue::Len(place) => {
let place = trans_place(fx, place);
let size = match place {
let usize_layout = fx.layout_of(fx.tcx.types.usize);
let len = match place.layout().ty.sty {
ty::Array(_elem_ty, len) => {
let len = crate::constant::force_eval_const(fx, len).unwrap_usize(fx.tcx) as i64;
fx.bcx.ins().iconst(fx.module.pointer_type(), len)
},
ty::Slice(_elem_ty) => match place {
CPlace::Addr(_, size, _) => size.unwrap(),
CPlace::Var(_, _) => unreachable!(),
}
_ => bug!("Rvalue::Len({:?})", place),
};
let usize_layout = fx.layout_of(fx.tcx.types.usize);
lval.write_cvalue(fx, CValue::ByVal(size, usize_layout));
lval.write_cvalue(fx, CValue::ByVal(len, usize_layout));
}
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
use crate::rustc::middle::lang_items::ExchangeMallocFnLangItem;

View file

@ -67,7 +67,7 @@ pub fn trans_constant<'a, 'tcx: 'a>(
trans_const_value(fx, const_)
}
fn force_eval_const<'a, 'tcx: 'a>(
pub fn force_eval_const<'a, 'tcx: 'a>(
fx: &FunctionCx<'a, 'tcx, impl Backend>,
const_: &'tcx Const<'tcx>,
) -> &'tcx Const<'tcx> {