@@ -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) ) ]
@@ -696,35 +697,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
696
697
OperandRef { val : OperandValue :: Immediate ( static_) , layout }
697
698
}
698
699
mir:: Rvalue :: Use ( ref operand) => self . codegen_operand ( bx, operand) ,
699
- mir:: Rvalue :: Aggregate ( box mir:: AggregateKind :: RawPtr ( ..) , ref fields) => {
700
- let ty = rvalue. ty ( self . mir , self . cx . tcx ( ) ) ;
701
- let layout = self . cx . layout_of ( self . monomorphize ( ty) ) ;
702
- let [ data, meta] = & * fields. raw else {
703
- bug ! ( "RawPtr fields: {fields:?}" ) ;
704
- } ;
705
- let data = self . codegen_operand ( bx, data) ;
706
- let meta = self . codegen_operand ( bx, meta) ;
707
- match ( data. val , meta. val ) {
708
- ( p @ OperandValue :: Immediate ( _) , OperandValue :: ZeroSized ) => {
709
- OperandRef { val : p, layout }
710
- }
711
- ( OperandValue :: Immediate ( p) , OperandValue :: Immediate ( m) ) => {
712
- OperandRef { val : OperandValue :: Pair ( p, m) , layout }
713
- }
714
- _ => bug ! ( "RawPtr operands {data:?} {meta:?}" ) ,
715
- }
716
- }
717
700
mir:: Rvalue :: Repeat ( ..) => bug ! ( "{rvalue:?} in codegen_rvalue_operand" ) ,
718
- mir:: Rvalue :: Aggregate ( _ , ref fields) => {
701
+ mir:: Rvalue :: Aggregate ( ref kind , ref fields) => {
719
702
let ty = rvalue. ty ( self . mir , self . cx . tcx ( ) ) ;
720
703
let ty = self . monomorphize ( ty) ;
721
704
let layout = self . cx . layout_of ( ty) ;
722
705
706
+ let field_indices = if let mir:: AggregateKind :: RawPtr ( ..) = * * kind {
707
+ // `index_by_increasing_offset` gives an empty iterator for primitives
708
+ Either :: Left ( [ 0_usize , 1_usize ] . iter ( ) . copied ( ) )
709
+ } else {
710
+ Either :: Right ( layout. fields . index_by_increasing_offset ( ) )
711
+ } ;
712
+ debug_assert_eq ! ( field_indices. len( ) , fields. len( ) ) ;
713
+
723
714
// `rvalue_creates_operand` has arranged that we only get here if
724
715
// we can build the aggregate immediate from the field immediates.
725
716
let mut inputs = ArrayVec :: < Bx :: Value , 2 > :: new ( ) ;
726
717
let mut input_scalars = ArrayVec :: < abi:: Scalar , 2 > :: new ( ) ;
727
- for field_idx in layout . fields . index_by_increasing_offset ( ) {
718
+ for field_idx in field_indices {
728
719
let field_idx = FieldIdx :: from_usize ( field_idx) ;
729
720
let op = self . codegen_operand ( bx, & fields[ field_idx] ) ;
730
721
let values = op. val . immediates_or_place ( ) . left_or_else ( |p| {
@@ -748,6 +739,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
748
739
) ;
749
740
750
741
let val = OperandValue :: from_immediates ( inputs) ;
742
+ debug_assert ! (
743
+ val. is_expected_variant_for_type( self . cx, layout) ,
744
+ "Made wrong variant {val:?} for type {layout:?}" ,
745
+ ) ;
751
746
OperandRef { val, layout }
752
747
}
753
748
mir:: Rvalue :: ShallowInitBox ( ref operand, content_ty) => {
@@ -792,7 +787,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
792
787
debug_assert ! (
793
788
if bx. cx( ) . type_has_metadata( ty) {
794
789
matches!( val, OperandValue :: Pair ( ..) )
795
- } else {
790
+ } else {
796
791
matches!( val, OperandValue :: Immediate ( ..) )
797
792
} ,
798
793
"Address of place was unexpectedly {val:?} for pointee type {ty:?}" ,
0 commit comments