Skip to content

Commit

Permalink
offset_of
Browse files Browse the repository at this point in the history
  • Loading branch information
beepster4096 committed Apr 21, 2023
1 parent fe3e383 commit 9dd0653
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,15 @@ fn codegen_stmt<'tcx>(
let operand = operand.load_scalar(fx);
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
}
Rvalue::NullaryOp(null_op, ty) => {
Rvalue::NullaryOp(ref null_op, ty) => {
assert!(lval.layout().ty.is_sized(fx.tcx, ParamEnv::reveal_all()));
let layout = fx.layout_of(fx.monomorphize(ty));
let val = match null_op {
NullOp::SizeOf => layout.size.bytes(),
NullOp::AlignOf => layout.align.abi.bytes(),
NullOp::OffsetOf(fields) => {
layout.offset_of_subfield(fx, fields.iter().map(|f| f.index())).bytes()
}
};
let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into());
lval.write_cvalue(fx, val);
Expand Down

0 comments on commit 9dd0653

Please sign in to comment.