@@ -72,8 +72,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
7272 if val. llextra . is_some ( ) {
7373 bug ! ( "unsized coercion on an unsized rvalue" ) ;
7474 }
75- let source = PlaceRef { val, layout : operand. layout } ;
76- base:: coerce_unsized_into ( bx, source, dest) ;
75+ base:: coerce_unsized_into ( bx, val. with_type ( operand. layout ) , dest) ;
7776 }
7877 OperandValue :: ZeroSized => {
7978 bug ! ( "unsized coercion on a ZST rvalue" ) ;
@@ -182,10 +181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
182181 OperandValue :: Immediate ( ..) | OperandValue :: Pair ( ..) => {
183182 // When we have immediate(s), the alignment of the source is irrelevant,
184183 // so we can store them using the destination's alignment.
185- src. val . store (
186- bx,
187- PlaceRef :: new_sized_aligned ( dst. val . llval , src. layout , dst. val . align ) ,
188- ) ;
184+ src. val . store ( bx, dst. val . with_type ( src. layout ) ) ;
189185 }
190186 }
191187 }
@@ -223,8 +219,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
223219 OperandValue :: Ref ( source_place_val) => {
224220 debug_assert_eq ! ( source_place_val. llextra, None ) ;
225221 debug_assert ! ( matches!( operand_kind, OperandValueKind :: Ref ) ) ;
226- let fake_place = PlaceRef { val : source_place_val, layout : cast } ;
227- Some ( bx. load_operand ( fake_place) . val )
222+ Some ( bx. load_operand ( source_place_val. with_type ( cast) ) . val )
228223 }
229224 OperandValue :: ZeroSized => {
230225 let OperandValueKind :: ZeroSized = operand_kind else {
@@ -452,23 +447,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
452447 }
453448 mir:: CastKind :: PointerCoercion ( PointerCoercion :: Unsize ) => {
454449 assert ! ( bx. cx( ) . is_backend_scalar_pair( cast) ) ;
455- let ( lldata, llextra) = match operand. val {
456- OperandValue :: Pair ( lldata, llextra) => {
457- // unsize from a fat pointer -- this is a
458- // "trait-object-to-supertrait" coercion.
459- ( lldata, Some ( llextra) )
460- }
461- OperandValue :: Immediate ( lldata) => {
462- // "standard" unsize
463- ( lldata, None )
464- }
465- OperandValue :: Ref ( ..) => {
466- bug ! ( "by-ref operand {:?} in `codegen_rvalue_operand`" , operand) ;
467- }
468- OperandValue :: ZeroSized => {
469- bug ! ( "zero-sized operand {:?} in `codegen_rvalue_operand`" , operand) ;
470- }
471- } ;
450+ let ( lldata, llextra) = operand. val . pointer_parts ( ) ;
472451 let ( lldata, llextra) =
473452 base:: unsize_ptr ( bx, lldata, operand. layout . ty , cast. ty , llextra) ;
474453 OperandValue :: Pair ( lldata, llextra)
@@ -489,12 +468,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
489468 }
490469 }
491470 mir:: CastKind :: DynStar => {
492- let ( lldata, llextra) = match operand. val {
493- OperandValue :: Ref ( ..) => todo ! ( ) ,
494- OperandValue :: Immediate ( v) => ( v, None ) ,
495- OperandValue :: Pair ( v, l) => ( v, Some ( l) ) ,
496- OperandValue :: ZeroSized => bug ! ( "ZST -- which is not PointerLike -- in DynStar" ) ,
497- } ;
471+ let ( lldata, llextra) = operand. val . pointer_parts ( ) ;
498472 let ( lldata, llextra) =
499473 base:: cast_to_dyn_star ( bx, lldata, operand. layout , cast. ty , llextra) ;
500474 OperandValue :: Pair ( lldata, llextra)
@@ -762,16 +736,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
762736 mk_ptr_ty : impl FnOnce ( TyCtxt < ' tcx > , Ty < ' tcx > ) -> Ty < ' tcx > ,
763737 ) -> OperandRef < ' tcx , Bx :: Value > {
764738 let cg_place = self . codegen_place ( bx, place. as_ref ( ) ) ;
739+ let val = cg_place. val . address ( ) ;
765740
766741 let ty = cg_place. layout . ty ;
742+ debug_assert ! (
743+ if bx. cx( ) . type_has_metadata( ty) {
744+ matches!( val, OperandValue :: Pair ( ..) )
745+ } else {
746+ matches!( val, OperandValue :: Immediate ( ..) )
747+ } ,
748+ "Address of place was unexpectedly {val:?} for pointee type {ty:?}" ,
749+ ) ;
767750
768- // Note: places are indirect, so storing the `llval` into the
769- // destination effectively creates a reference.
770- let val = if !bx. cx ( ) . type_has_metadata ( ty) {
771- OperandValue :: Immediate ( cg_place. val . llval )
772- } else {
773- OperandValue :: Pair ( cg_place. val . llval , cg_place. val . llextra . unwrap ( ) )
774- } ;
775751 OperandRef { val, layout : self . cx . layout_of ( mk_ptr_ty ( self . cx . tcx ( ) , ty) ) }
776752 }
777753
0 commit comments