about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2024-04-11 21:45:05 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2024-04-21 11:08:37 -0700
commite654877b2fe85e168513add63552149fdddc2ff7 (patch)
treeff9f0c37648c8df71d2aff70a337111b9cdfa9f7 /src
parentbe9d7ca97763ad0c613b7ed57ae113e63b32dbe8 (diff)
downloadrust-e654877b2fe85e168513add63552149fdddc2ff7.tar.gz
rust-e654877b2fe85e168513add63552149fdddc2ff7.zip
Also handle AggregateKind::RawPtr in cg_cranelift
Diffstat (limited to 'src')
-rw-r--r--src/base.rs13
-rw-r--r--src/value_and_place.rs17
2 files changed, 30 insertions, 0 deletions
diff --git a/src/base.rs b/src/base.rs
index f07421431da..f428c4c7c0d 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -813,6 +813,19 @@ fn codegen_stmt<'tcx>(
                     );
                     lval.write_cvalue(fx, val);
                 }
+                Rvalue::Aggregate(ref kind, ref operands)
+                    if matches!(**kind, AggregateKind::RawPtr(..)) =>
+                {
+                    let ty = to_place_and_rval.1.ty(&fx.mir.local_decls, fx.tcx);
+                    let layout = fx.layout_of(fx.monomorphize(ty));
+                    let [data, meta] = &*operands.raw else {
+                        bug!("RawPtr fields: {operands:?}");
+                    };
+                    let data = codegen_operand(fx, data);
+                    let meta = codegen_operand(fx, meta);
+                    let ptr_val = CValue::pointer_from_data_and_meta(data, meta, layout);
+                    lval.write_cvalue(fx, ptr_val);
+                }
                 Rvalue::Aggregate(ref kind, ref operands) => {
                     let (variant_index, variant_dest, active_field_index) = match **kind {
                         mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
diff --git a/src/value_and_place.rs b/src/value_and_place.rs
index ad863903cee..8d52fd9d7a8 100644
--- a/src/value_and_place.rs
+++ b/src/value_and_place.rs
@@ -94,6 +94,23 @@ impl<'tcx> CValue<'tcx> {
         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(
+        data: CValue<'tcx>,
+        meta: CValue<'tcx>,
+        layout: TyAndLayout<'tcx>,
+    ) -> CValue<'tcx> {
+        assert!(layout.ty.is_unsafe_ptr());
+        let inner = match (data.0, meta.0) {
+            (CValueInner::ByVal(p), CValueInner::ByVal(m)) => CValueInner::ByValPair(p, m),
+            (p @ CValueInner::ByVal(_), CValueInner::ByRef(..)) if meta.1.is_zst() => p,
+            _ => bug!("RawPtr operands {data:?} {meta:?}"),
+        };
+        CValue(inner, layout)
+    }
+
     pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
         self.1
     }