Skip to content

Commit fa4a377

Browse files
committed
Rvalue::Len
1 parent 12282a8 commit fa4a377

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/base.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,15 @@ fn trans_stmt<'a, 'tcx: 'a>(
474474
to.write_cvalue(fx, operand);
475475
}
476476
}
477-
Rvalue::Len(lval) => unimpl!("rval len {:?}", lval),
477+
Rvalue::Len(place) => {
478+
let place = trans_place(fx, place);
479+
let size = match place {
480+
CPlace::Addr(_, size, _) => size.unwrap(),
481+
CPlace::Var(_, _) => unreachable!(),
482+
};
483+
let usize_layout = fx.layout_of(fx.tcx.types.usize);
484+
lval.write_cvalue(fx, CValue::ByVal(size, usize_layout));
485+
}
478486
Rvalue::NullaryOp(NullOp::Box, ty) => unimplemented!("rval box {:?}", ty),
479487
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
480488
assert!(

src/common.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,23 +433,20 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
433433
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
434434
index: Value,
435435
) -> CPlace<'tcx> {
436-
let addr = self.expect_addr();
437-
let layout = self.layout();
438-
if layout.is_unsized() {
439-
unimpl!("unsized place_field");
440-
}
441-
442-
match layout.ty.sty {
436+
match self.layout().ty.sty {
443437
ty::Array(elem_ty, _) => {
444438
let elem_layout = fx.layout_of(elem_ty);
439+
445440
let offset = fx
446441
.bcx
447442
.ins()
448443
.imul_imm(index, elem_layout.size.bytes() as i64);
444+
445+
let addr = self.expect_addr();
449446
CPlace::Addr(fx.bcx.ins().iadd(addr, offset), None, elem_layout)
450447
}
451-
ty::Slice(_elem_ty) => unimplemented!("place_index(TySlice)"),
452-
_ => bug!("place_index({:?})", layout.ty),
448+
ty::Slice(_elem_ty) => unimpl!("place_index(TySlice)"),
449+
_ => bug!("place_index({:?})", self.layout().ty),
453450
}
454451
}
455452

0 commit comments

Comments
 (0)