@@ -566,6 +566,25 @@ fn cast_shift_rhs<F, G>(op: ast::BinOp_,
566
566
}
567
567
}
568
568
569
+ pub fn llty_and_min_for_signed_ty < ' blk , ' tcx > ( cx : Block < ' blk , ' tcx > ,
570
+ val_t : Ty < ' tcx > ) -> ( Type , u64 ) {
571
+ match val_t. sty {
572
+ ty:: ty_int( t) => {
573
+ let llty = Type :: int_from_ty ( cx. ccx ( ) , t) ;
574
+ let min = match t {
575
+ ast:: TyIs if llty == Type :: i32 ( cx. ccx ( ) ) => i32:: MIN as u64 ,
576
+ ast:: TyIs => i64:: MIN as u64 ,
577
+ ast:: TyI8 => i8:: MIN as u64 ,
578
+ ast:: TyI16 => i16:: MIN as u64 ,
579
+ ast:: TyI32 => i32:: MIN as u64 ,
580
+ ast:: TyI64 => i64:: MIN as u64 ,
581
+ } ;
582
+ ( llty, min)
583
+ }
584
+ _ => unreachable ! ( ) ,
585
+ }
586
+ }
587
+
569
588
pub fn fail_if_zero_or_overflows < ' blk , ' tcx > (
570
589
cx : Block < ' blk , ' tcx > ,
571
590
call_info : NodeIdAndSpan ,
@@ -620,21 +639,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
620
639
// signed division/remainder which would trigger overflow. For unsigned
621
640
// integers, no action beyond checking for zero need be taken.
622
641
if is_signed {
623
- let ( llty, min) = match rhs_t. sty {
624
- ty:: ty_int( t) => {
625
- let llty = Type :: int_from_ty ( cx. ccx ( ) , t) ;
626
- let min = match t {
627
- ast:: TyIs if llty == Type :: i32 ( cx. ccx ( ) ) => i32:: MIN as u64 ,
628
- ast:: TyIs => i64:: MIN as u64 ,
629
- ast:: TyI8 => i8:: MIN as u64 ,
630
- ast:: TyI16 => i16:: MIN as u64 ,
631
- ast:: TyI32 => i32:: MIN as u64 ,
632
- ast:: TyI64 => i64:: MIN as u64 ,
633
- } ;
634
- ( llty, min)
635
- }
636
- _ => unreachable ! ( ) ,
637
- } ;
642
+ let ( llty, min) = llty_and_min_for_signed_ty ( cx, rhs_t) ;
638
643
let minus_one = ICmp ( bcx, llvm:: IntEQ , rhs,
639
644
C_integral ( llty, !0 , false ) , debug_loc) ;
640
645
with_cond ( bcx, minus_one, |bcx| {
0 commit comments