@@ -18,6 +18,7 @@ use rustc_span::{Span, DUMMY_SP};
18
18
use rustc_target:: abi:: { self , FieldIdx , FIRST_VARIANT } ;
19
19
20
20
use arrayvec:: ArrayVec ;
21
+ use either:: Either ;
21
22
22
23
impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
23
24
#[ instrument( level = "trace" , skip( self , bx) ) ]
@@ -722,35 +723,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
722
723
OperandRef { val : OperandValue :: Immediate ( static_) , layout }
723
724
}
724
725
mir:: Rvalue :: Use ( ref operand) => self . codegen_operand ( bx, operand) ,
725
- mir:: Rvalue :: Aggregate ( box mir:: AggregateKind :: RawPtr ( ..) , ref fields) => {
726
- let ty = rvalue. ty ( self . mir , self . cx . tcx ( ) ) ;
727
- let layout = self . cx . layout_of ( self . monomorphize ( ty) ) ;
728
- let [ data, meta] = & * fields. raw else {
729
- bug ! ( "RawPtr fields: {fields:?}" ) ;
730
- } ;
731
- let data = self . codegen_operand ( bx, data) ;
732
- let meta = self . codegen_operand ( bx, meta) ;
733
- match ( data. val , meta. val ) {
734
- ( p @ OperandValue :: Immediate ( _) , OperandValue :: ZeroSized ) => {
735
- OperandRef { val : p, layout }
736
- }
737
- ( OperandValue :: Immediate ( p) , OperandValue :: Immediate ( m) ) => {
738
- OperandRef { val : OperandValue :: Pair ( p, m) , layout }
739
- }
740
- _ => bug ! ( "RawPtr operands {data:?} {meta:?}" ) ,
741
- }
742
- }
743
726
mir:: Rvalue :: Repeat ( ..) => bug ! ( "{rvalue:?} in codegen_rvalue_operand" ) ,
744
- mir:: Rvalue :: Aggregate ( _ , ref fields) => {
727
+ mir:: Rvalue :: Aggregate ( ref kind , ref fields) => {
745
728
let ty = rvalue. ty ( self . mir , self . cx . tcx ( ) ) ;
746
729
let ty = self . monomorphize ( ty) ;
747
730
let layout = self . cx . layout_of ( ty) ;
748
731
732
+ let field_indices = if let mir:: AggregateKind :: RawPtr ( ..) = * * kind {
733
+ // `index_by_increasing_offset` gives an empty iterator for primitives
734
+ Either :: Left ( [ 0_usize , 1_usize ] . iter ( ) . copied ( ) )
735
+ } else {
736
+ Either :: Right ( layout. fields . index_by_increasing_offset ( ) )
737
+ } ;
738
+ debug_assert_eq ! ( field_indices. len( ) , fields. len( ) ) ;
739
+
749
740
// `rvalue_creates_operand` has arranged that we only get here if
750
741
// we can build the aggregate immediate from the field immediates.
751
742
let mut inputs = ArrayVec :: < Bx :: Value , 2 > :: new ( ) ;
752
743
let mut input_scalars = ArrayVec :: < abi:: Scalar , 2 > :: new ( ) ;
753
- for field_idx in layout . fields . index_by_increasing_offset ( ) {
744
+ for field_idx in field_indices {
754
745
let field_idx = FieldIdx :: from_usize ( field_idx) ;
755
746
let op = self . codegen_operand ( bx, & fields[ field_idx] ) ;
756
747
let values = op. val . immediates_or_place ( ) . left_or_else ( |p| {
@@ -774,6 +765,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
774
765
) ;
775
766
776
767
let val = OperandValue :: from_immediates ( inputs) ;
768
+ debug_assert ! (
769
+ val. is_expected_variant_for_type( self . cx, layout) ,
770
+ "Made wrong variant {val:?} for type {layout:?}" ,
771
+ ) ;
777
772
OperandRef { val, layout }
778
773
}
779
774
mir:: Rvalue :: ShallowInitBox ( ref operand, content_ty) => {
0 commit comments