@@ -664,9 +664,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
664664                        lhs. layout . ty , 
665665                    ) , 
666666
667-                     ( OperandValue :: Immediate ( lhs_val) ,  OperandValue :: Immediate ( rhs_val) )  => { 
668-                         self . codegen_scalar_binop ( bx,  op,  lhs_val,  rhs_val,  lhs. layout . ty ) 
669-                     } 
667+                     ( OperandValue :: Immediate ( lhs_val) ,  OperandValue :: Immediate ( rhs_val) )  => self 
668+                         . codegen_scalar_binop ( 
669+                             bx, 
670+                             op, 
671+                             lhs_val, 
672+                             rhs_val, 
673+                             lhs. layout . ty , 
674+                             rhs. layout . ty , 
675+                         ) , 
670676
671677                    _ => bug ! ( ) , 
672678                } ; 
@@ -887,10 +893,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
887893        op :  mir:: BinOp , 
888894        lhs :  Bx :: Value , 
889895        rhs :  Bx :: Value , 
890-         input_ty :  Ty < ' tcx > , 
896+         lhs_ty :  Ty < ' tcx > , 
897+         rhs_ty :  Ty < ' tcx > , 
891898    )  -> Bx :: Value  { 
892-         let  is_float = input_ty . is_floating_point ( ) ; 
893-         let  is_signed = input_ty . is_signed ( ) ; 
899+         let  is_float = lhs_ty . is_floating_point ( ) ; 
900+         let  is_signed = lhs_ty . is_signed ( ) ; 
894901        match  op { 
895902            mir:: BinOp :: Add  => { 
896903                if  is_float { 
@@ -956,17 +963,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
956963            mir:: BinOp :: BitAnd  => bx. and ( lhs,  rhs) , 
957964            mir:: BinOp :: BitXor  => bx. xor ( lhs,  rhs) , 
958965            mir:: BinOp :: Offset  => { 
959-                 let  pointee_type = input_ty 
966+                 let  pointee_type = lhs_ty 
960967                    . builtin_deref ( true ) 
961-                     . unwrap_or_else ( || bug ! ( "deref of non-pointer {:?}" ,  input_ty ) ) ; 
968+                     . unwrap_or_else ( || bug ! ( "deref of non-pointer {:?}" ,  lhs_ty ) ) ; 
962969                let  pointee_layout = bx. cx ( ) . layout_of ( pointee_type) ; 
963970                if  pointee_layout. is_zst ( )  { 
964971                    // `Offset` works in terms of the size of pointee, 
965972                    // so offsetting a pointer to ZST is a noop. 
966973                    lhs
967974                }  else  { 
968975                    let  llty = bx. cx ( ) . backend_type ( pointee_layout) ; 
969-                     bx. inbounds_gep ( llty,  lhs,  & [ rhs] ) 
976+                     if  !rhs_ty. is_signed ( )  { 
977+                         bx. inbounds_nuw_gep ( llty,  lhs,  & [ rhs] ) 
978+                     }  else  { 
979+                         bx. inbounds_gep ( llty,  lhs,  & [ rhs] ) 
980+                     } 
970981                } 
971982            } 
972983            mir:: BinOp :: Shl  | mir:: BinOp :: ShlUnchecked  => { 
0 commit comments