@@ -570,7 +570,9 @@ fn trans_stmt<'a, 'tcx: 'a>(
570
570
lval. write_cvalue ( fx, CValue :: ByVal ( res, dest_layout) ) ;
571
571
}
572
572
( ty:: Adt ( adt_def, _substs) , ty:: Uint ( _) ) | ( ty:: Adt ( adt_def, _substs) , ty:: Int ( _) ) if adt_def. is_enum ( ) => {
573
- let discr = trans_get_discriminant ( fx, operand, fx. layout_of ( to_ty) ) ;
573
+ // FIXME avoid forcing to stack
574
+ let place = CPlace :: Addr ( operand. force_stack ( fx) , None , operand. layout ( ) ) ;
575
+ let discr = trans_get_discriminant ( fx, place, fx. layout_of ( to_ty) ) ;
574
576
lval. write_cvalue ( fx, discr) ;
575
577
}
576
578
_ => unimpl ! ( "rval misc {:?} {:?}" , from_ty, to_ty) ,
@@ -584,7 +586,7 @@ fn trans_stmt<'a, 'tcx: 'a>(
584
586
operand. unsize_value ( fx, lval) ;
585
587
}
586
588
Rvalue :: Discriminant ( place) => {
587
- let place = trans_place ( fx, place) . to_cvalue ( fx ) ;
589
+ let place = trans_place ( fx, place) ;
588
590
let discr = trans_get_discriminant ( fx, place, dest_layout) ;
589
591
lval. write_cvalue ( fx, discr) ;
590
592
}
@@ -680,10 +682,10 @@ fn codegen_array_len<'a, 'tcx: 'a>(
680
682
681
683
pub fn trans_get_discriminant < ' a , ' tcx : ' a > (
682
684
fx : & mut FunctionCx < ' a , ' tcx , impl Backend > ,
683
- value : CValue < ' tcx > ,
685
+ place : CPlace < ' tcx > ,
684
686
dest_layout : TyLayout < ' tcx > ,
685
687
) -> CValue < ' tcx > {
686
- let layout = value . layout ( ) ;
688
+ let layout = place . layout ( ) ;
687
689
688
690
if layout. abi == layout:: Abi :: Uninhabited {
689
691
trap_unreachable ( & mut fx. bcx ) ;
@@ -701,7 +703,7 @@ pub fn trans_get_discriminant<'a, 'tcx: 'a>(
701
703
layout:: Variants :: Tagged { .. } | layout:: Variants :: NicheFilling { .. } => { }
702
704
}
703
705
704
- let discr = value . value_field ( fx, mir:: Field :: new ( 0 ) ) ;
706
+ let discr = place . place_field ( fx, mir:: Field :: new ( 0 ) ) . to_cvalue ( fx ) ;
705
707
let discr_ty = discr. layout ( ) . ty ;
706
708
let lldiscr = discr. load_scalar ( fx) ;
707
709
match layout. variants {
0 commit comments