@@ -9,7 +9,7 @@ use crate::MemFlags;
99
1010use rustc_hir as hir;
1111use rustc_middle:: mir;
12- use rustc_middle:: mir:: Operand ;
12+ use rustc_middle:: mir:: { AggregateKind , Operand } ;
1313use rustc_middle:: ty:: cast:: { CastTy , IntTy } ;
1414use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf , TyAndLayout } ;
1515use rustc_middle:: ty:: { self , adjustment:: PointerCoercion , Instance , Ty , TyCtxt } ;
@@ -717,6 +717,24 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
717717 OperandRef { val : OperandValue :: Immediate ( static_) , layout }
718718 }
719719 mir:: Rvalue :: Use ( ref operand) => self . codegen_operand ( bx, operand) ,
720+ mir:: Rvalue :: Aggregate ( box mir:: AggregateKind :: RawPtr ( ..) , ref fields) => {
721+ let ty = rvalue. ty ( self . mir , self . cx . tcx ( ) ) ;
722+ let layout = self . cx . layout_of ( self . monomorphize ( ty) ) ;
723+ let [ data, meta] = & * fields. raw else {
724+ bug ! ( "RawPtr fields: {fields:?}" ) ;
725+ } ;
726+ let data = self . codegen_operand ( bx, data) ;
727+ let meta = self . codegen_operand ( bx, meta) ;
728+ match ( data. val , meta. val ) {
729+ ( p @ OperandValue :: Immediate ( _) , OperandValue :: ZeroSized ) => {
730+ OperandRef { val : p, layout }
731+ }
732+ ( OperandValue :: Immediate ( p) , OperandValue :: Immediate ( m) ) => {
733+ OperandRef { val : OperandValue :: Pair ( p, m) , layout }
734+ }
735+ _ => bug ! ( "RawPtr operands {data:?} {meta:?}" ) ,
736+ }
737+ }
720738 mir:: Rvalue :: Repeat ( ..) | mir:: Rvalue :: Aggregate ( ..) => {
721739 // According to `rvalue_creates_operand`, only ZST
722740 // aggregate rvalues are allowed to be operands.
@@ -1029,6 +1047,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10291047 mir:: Rvalue :: ThreadLocalRef ( _) |
10301048 mir:: Rvalue :: Use ( ..) => // (*)
10311049 true ,
1050+ // This always produces a `ty::RawPtr`, so will be Immediate or Pair
1051+ mir:: Rvalue :: Aggregate ( box AggregateKind :: RawPtr ( ..) , ..) => true ,
10321052 mir:: Rvalue :: Repeat ( ..) |
10331053 mir:: Rvalue :: Aggregate ( ..) => {
10341054 let ty = rvalue. ty ( self . mir , self . cx . tcx ( ) ) ;
0 commit comments