@@ -793,43 +793,40 @@ pub fn trans_switch<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
793
793
}
794
794
}
795
795
796
-
796
+ pub fn is_discr_signed < ' tcx > ( r : & Repr < ' tcx > ) -> bool {
797
+ match * r {
798
+ CEnum ( ity, _, _) => ity. is_signed ( ) ,
799
+ General ( ity, _, _) => ity. is_signed ( ) ,
800
+ Univariant ( ..) => false ,
801
+ RawNullablePointer { .. } => false ,
802
+ StructWrappedNullablePointer { .. } => false ,
803
+ }
804
+ }
797
805
798
806
/// Obtain the actual discriminant of a value.
799
807
pub fn trans_get_discr < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , r : & Repr < ' tcx > ,
800
808
scrutinee : ValueRef , cast_to : Option < Type > )
801
809
-> ValueRef {
802
- let signed;
803
- let val;
804
810
debug ! ( "trans_get_discr r: {:?}" , r) ;
805
- match * r {
806
- CEnum ( ity, min, max) => {
807
- val = load_discr ( bcx, ity, scrutinee, min, max) ;
808
- signed = ity. is_signed ( ) ;
809
- }
811
+ let val = match * r {
812
+ CEnum ( ity, min, max) => load_discr ( bcx, ity, scrutinee, min, max) ,
810
813
General ( ity, ref cases, _) => {
811
814
let ptr = GEPi ( bcx, scrutinee, & [ 0 , 0 ] ) ;
812
- val = load_discr ( bcx, ity, ptr, 0 , ( cases. len ( ) - 1 ) as Disr ) ;
813
- signed = ity. is_signed ( ) ;
814
- }
815
- Univariant ( ..) => {
816
- val = C_u8 ( bcx. ccx ( ) , 0 ) ;
817
- signed = false ;
815
+ load_discr ( bcx, ity, ptr, 0 , ( cases. len ( ) - 1 ) as Disr )
818
816
}
817
+ Univariant ( ..) => C_u8 ( bcx. ccx ( ) , 0 ) ,
819
818
RawNullablePointer { nndiscr, nnty, .. } => {
820
819
let cmp = if nndiscr == 0 { IntEQ } else { IntNE } ;
821
820
let llptrty = type_of:: sizing_type_of ( bcx. ccx ( ) , nnty) ;
822
- val = ICmp ( bcx, cmp, Load ( bcx, scrutinee) , C_null ( llptrty) , DebugLoc :: None ) ;
823
- signed = false ;
821
+ ICmp ( bcx, cmp, Load ( bcx, scrutinee) , C_null ( llptrty) , DebugLoc :: None )
824
822
}
825
823
StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
826
- val = struct_wrapped_nullable_bitdiscr ( bcx, nndiscr, discrfield, scrutinee) ;
827
- signed = false ;
824
+ struct_wrapped_nullable_bitdiscr ( bcx, nndiscr, discrfield, scrutinee)
828
825
}
829
- }
826
+ } ;
830
827
match cast_to {
831
828
None => val,
832
- Some ( llty) => if signed { SExt ( bcx, val, llty) } else { ZExt ( bcx, val, llty) }
829
+ Some ( llty) => if is_discr_signed ( r ) { SExt ( bcx, val, llty) } else { ZExt ( bcx, val, llty) }
833
830
}
834
831
}
835
832
0 commit comments