Skip to content

Commit 3cf58a9

Browse files
committed
Also handle AggregateKind::RawPtr in cg_cranelift
1 parent dbb5a09 commit 3cf58a9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

+11
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,17 @@ fn codegen_stmt<'tcx>(
804804
);
805805
lval.write_cvalue(fx, val);
806806
}
807+
Rvalue::Aggregate(ref kind, ref operands) if matches!(**kind, AggregateKind::RawPtr(..)) => {
808+
let ty = to_place_and_rval.1.ty(&fx.mir.local_decls, fx.tcx);
809+
let layout = fx.layout_of(fx.monomorphize(ty));
810+
let [data, meta] = &*operands.raw else {
811+
bug!("RawPtr fields: {operands:?}");
812+
};
813+
let data = codegen_operand(fx, data);
814+
let meta = codegen_operand(fx, meta);
815+
let ptr_val = CValue::pointer_from_data_and_meta(data, meta, layout);
816+
lval.write_cvalue(fx, ptr_val);
817+
}
807818
Rvalue::Aggregate(ref kind, ref operands) => {
808819
let (variant_index, variant_dest, active_field_index) = match **kind {
809820
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+17
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ impl<'tcx> CValue<'tcx> {
9494
CValue(CValueInner::ByValPair(value, extra), layout)
9595
}
9696

97+
/// For `AggregateKind::RawPtr`, create a pointer from its parts.
98+
///
99+
/// Panics if the `layout` is not a raw pointer.
100+
pub(crate) fn pointer_from_data_and_meta(
101+
data: CValue<'tcx>,
102+
meta: CValue<'tcx>,
103+
layout: TyAndLayout<'tcx>,
104+
) -> CValue<'tcx> {
105+
assert!(layout.ty.is_unsafe_ptr());
106+
let inner = match (data.0, meta.0) {
107+
(CValueInner::ByVal(p), CValueInner::ByVal(m)) => CValueInner::ByValPair(p, m),
108+
(p @ CValueInner::ByVal(_), CValueInner::ByRef(..)) if meta.1.is_zst() => p,
109+
_ => bug!("RawPtr operands {data:?} {meta:?}"),
110+
};
111+
CValue(inner, layout)
112+
}
113+
97114
pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
98115
self.1
99116
}

0 commit comments

Comments
 (0)