Skip to content

Commit 02d3c13

Browse files
committed
Auto merge of rust-lang#88839 - nbdd0121:alignof, r=nagisa
Introduce NullOp::AlignOf This PR introduces `Rvalue::NullaryOp(NullOp::AlignOf, ty)`, which will be lowered from `align_of`, similar to `size_of` lowering to `Rvalue::NullaryOp(NullOp::SizeOf, ty)`. The changes are originally part of rust-lang#88700 but since it's not dependent on other changes and could have performance impact on its own, it's separated into its own PR.
2 parents a81217c + 4ac4980 commit 02d3c13

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/base.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -726,15 +726,20 @@ fn codegen_stmt<'tcx>(
726726
let ptr = fx.bcx.inst_results(call)[0];
727727
lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
728728
}
729-
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
729+
Rvalue::NullaryOp(null_op, ty) => {
730730
assert!(
731731
lval.layout()
732732
.ty
733733
.is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all())
734734
);
735-
let ty_size = fx.layout_of(fx.monomorphize(ty)).size.bytes();
735+
let layout = fx.layout_of(fx.monomorphize(ty));
736+
let val = match null_op {
737+
NullOp::SizeOf => layout.size.bytes(),
738+
NullOp::AlignOf => layout.align.abi.bytes(),
739+
NullOp::Box => unreachable!(),
740+
};
736741
let val =
737-
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
742+
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into());
738743
lval.write_cvalue(fx, val);
739744
}
740745
Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() {

src/intrinsics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
823823
dest.write_cvalue(fx, val);
824824
};
825825

826-
pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
826+
pref_align_of | needs_drop | type_id | type_name | variant_count, () {
827827
let const_val =
828828
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
829829
let val = crate::constant::codegen_const_value(

0 commit comments

Comments
 (0)