Inline CValue::pointer_from_data_and_meta

It only has a single use and doesn't need access to CValue internals.
This commit is contained in:
bjorn3 2024-04-22 17:03:48 +00:00
parent 8bf1687879
commit 569df1dad3
2 changed files with 7 additions and 19 deletions

View File

@ -825,7 +825,13 @@ fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
}; };
let data = codegen_operand(fx, data); let data = codegen_operand(fx, data);
let meta = codegen_operand(fx, meta); let meta = codegen_operand(fx, meta);
let ptr_val = CValue::pointer_from_data_and_meta(fx, data, meta, layout); assert!(data.layout().ty.is_unsafe_ptr());
assert!(layout.ty.is_unsafe_ptr());
let ptr_val = if meta.layout().is_zst() {
data.cast_pointer_to(layout)
} else {
CValue::by_val_pair(data.load_scalar(fx), meta.load_scalar(fx), layout)
};
lval.write_cvalue(fx, ptr_val); lval.write_cvalue(fx, ptr_val);
} }
Rvalue::Aggregate(ref kind, ref operands) => { Rvalue::Aggregate(ref kind, ref operands) => {

View File

@ -95,24 +95,6 @@ pub(crate) fn by_val_pair(
CValue(CValueInner::ByValPair(value, extra), layout) CValue(CValueInner::ByValPair(value, extra), layout)
} }
/// For `AggregateKind::RawPtr`, create a pointer from its parts.
///
/// Panics if the `layout` is not a raw pointer.
pub(crate) fn pointer_from_data_and_meta(
fx: &mut FunctionCx<'_, '_, 'tcx>,
data: CValue<'tcx>,
meta: CValue<'tcx>,
layout: TyAndLayout<'tcx>,
) -> CValue<'tcx> {
assert!(data.layout().ty.is_unsafe_ptr());
assert!(layout.ty.is_unsafe_ptr());
if meta.layout().is_zst() {
data.cast_pointer_to(layout)
} else {
CValue::by_val_pair(data.load_scalar(fx), meta.load_scalar(fx), layout)
}
}
pub(crate) fn layout(&self) -> TyAndLayout<'tcx> { pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
self.1 self.1
} }