@@ -72,8 +72,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
72
72
if val. llextra . is_some ( ) {
73
73
bug ! ( "unsized coercion on an unsized rvalue" ) ;
74
74
}
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) ;
77
76
}
78
77
OperandValue :: ZeroSized => {
79
78
bug ! ( "unsized coercion on a ZST rvalue" ) ;
@@ -182,10 +181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
182
181
OperandValue :: Immediate ( ..) | OperandValue :: Pair ( ..) => {
183
182
// When we have immediate(s), the alignment of the source is irrelevant,
184
183
// 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 ) ) ;
189
185
}
190
186
}
191
187
}
@@ -223,8 +219,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
223
219
OperandValue :: Ref ( source_place_val) => {
224
220
debug_assert_eq ! ( source_place_val. llextra, None ) ;
225
221
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 )
228
223
}
229
224
OperandValue :: ZeroSized => {
230
225
let OperandValueKind :: ZeroSized = operand_kind else {
@@ -452,23 +447,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
452
447
}
453
448
mir:: CastKind :: PointerCoercion ( PointerCoercion :: Unsize ) => {
454
449
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 ( ) ;
472
451
let ( lldata, llextra) =
473
452
base:: unsize_ptr ( bx, lldata, operand. layout . ty , cast. ty , llextra) ;
474
453
OperandValue :: Pair ( lldata, llextra)
@@ -489,12 +468,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
489
468
}
490
469
}
491
470
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 ( ) ;
498
472
let ( lldata, llextra) =
499
473
base:: cast_to_dyn_star ( bx, lldata, operand. layout , cast. ty , llextra) ;
500
474
OperandValue :: Pair ( lldata, llextra)
@@ -762,16 +736,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
762
736
mk_ptr_ty : impl FnOnce ( TyCtxt < ' tcx > , Ty < ' tcx > ) -> Ty < ' tcx > ,
763
737
) -> OperandRef < ' tcx , Bx :: Value > {
764
738
let cg_place = self . codegen_place ( bx, place. as_ref ( ) ) ;
739
+ let val = cg_place. val . address ( ) ;
765
740
766
741
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
+ ) ;
767
750
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
- } ;
775
751
OperandRef { val, layout : self . cx . layout_of ( mk_ptr_ty ( self . cx . tcx ( ) , ty) ) }
776
752
}
777
753
0 commit comments