@@ -664,9 +664,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
664
664
lhs. layout . ty ,
665
665
) ,
666
666
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
+ ) ,
670
676
671
677
_ => bug ! ( ) ,
672
678
} ;
@@ -887,10 +893,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
887
893
op : mir:: BinOp ,
888
894
lhs : Bx :: Value ,
889
895
rhs : Bx :: Value ,
890
- input_ty : Ty < ' tcx > ,
896
+ lhs_ty : Ty < ' tcx > ,
897
+ rhs_ty : Ty < ' tcx > ,
891
898
) -> 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 ( ) ;
894
901
match op {
895
902
mir:: BinOp :: Add => {
896
903
if is_float {
@@ -956,17 +963,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
956
963
mir:: BinOp :: BitAnd => bx. and ( lhs, rhs) ,
957
964
mir:: BinOp :: BitXor => bx. xor ( lhs, rhs) ,
958
965
mir:: BinOp :: Offset => {
959
- let pointee_type = input_ty
966
+ let pointee_type = lhs_ty
960
967
. 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 ) ) ;
962
969
let pointee_layout = bx. cx ( ) . layout_of ( pointee_type) ;
963
970
if pointee_layout. is_zst ( ) {
964
971
// `Offset` works in terms of the size of pointee,
965
972
// so offsetting a pointer to ZST is a noop.
966
973
lhs
967
974
} else {
968
975
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
+ }
970
981
}
971
982
}
972
983
mir:: BinOp :: Shl | mir:: BinOp :: ShlUnchecked => {
0 commit comments