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