@@ -572,6 +572,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
572572 }
573573 }
574574
575+ mir:: Rvalue :: BinaryOp ( op_with_overflow, box ( ref lhs, ref rhs) )
576+ if let Some ( op) = op_with_overflow. overflowing_to_wrapping ( ) =>
577+ {
578+ let lhs = self . codegen_operand ( bx, lhs) ;
579+ let rhs = self . codegen_operand ( bx, rhs) ;
580+ let result = self . codegen_scalar_checked_binop (
581+ bx,
582+ op,
583+ lhs. immediate ( ) ,
584+ rhs. immediate ( ) ,
585+ lhs. layout . ty ,
586+ ) ;
587+ let val_ty = op. ty ( bx. tcx ( ) , lhs. layout . ty , rhs. layout . ty ) ;
588+ let operand_ty = Ty :: new_tup ( bx. tcx ( ) , & [ val_ty, bx. tcx ( ) . types . bool ] ) ;
589+ OperandRef { val : result, layout : bx. cx ( ) . layout_of ( operand_ty) }
590+ }
575591 mir:: Rvalue :: BinaryOp ( op, box ( ref lhs, ref rhs) ) => {
576592 let lhs = self . codegen_operand ( bx, lhs) ;
577593 let rhs = self . codegen_operand ( bx, rhs) ;
@@ -600,20 +616,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
600616 layout : bx. cx ( ) . layout_of ( op. ty ( bx. tcx ( ) , lhs. layout . ty , rhs. layout . ty ) ) ,
601617 }
602618 }
603- mir:: Rvalue :: CheckedBinaryOp ( op, box ( ref lhs, ref rhs) ) => {
604- let lhs = self . codegen_operand ( bx, lhs) ;
605- let rhs = self . codegen_operand ( bx, rhs) ;
606- let result = self . codegen_scalar_checked_binop (
607- bx,
608- op,
609- lhs. immediate ( ) ,
610- rhs. immediate ( ) ,
611- lhs. layout . ty ,
612- ) ;
613- let val_ty = op. ty ( bx. tcx ( ) , lhs. layout . ty , rhs. layout . ty ) ;
614- let operand_ty = Ty :: new_tup ( bx. tcx ( ) , & [ val_ty, bx. tcx ( ) . types . bool ] ) ;
615- OperandRef { val : result, layout : bx. cx ( ) . layout_of ( operand_ty) }
616- }
617619
618620 mir:: Rvalue :: UnaryOp ( op, ref operand) => {
619621 let operand = self . codegen_operand ( bx, operand) ;
@@ -792,7 +794,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
792794 debug_assert ! (
793795 if bx. cx( ) . type_has_metadata( ty) {
794796 matches!( val, OperandValue :: Pair ( ..) )
795- } else {
797+ } else {
796798 matches!( val, OperandValue :: Immediate ( ..) )
797799 } ,
798800 "Address of place was unexpectedly {val:?} for pointee type {ty:?}" ,
@@ -938,6 +940,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
938940 bx. select ( is_lt, bx. cx ( ) . const_i8 ( Ordering :: Less as i8 ) , ge)
939941 }
940942 }
943+ mir:: BinOp :: AddWithOverflow
944+ | mir:: BinOp :: SubWithOverflow
945+ | mir:: BinOp :: MulWithOverflow => {
946+ bug ! ( "{op:?} needs to return a pair, so call codegen_scalar_checked_binop instead" )
947+ }
941948 }
942949 }
943950
@@ -1050,7 +1057,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10501057 mir:: Rvalue :: Cast ( ..) | // (*)
10511058 mir:: Rvalue :: ShallowInitBox ( ..) | // (*)
10521059 mir:: Rvalue :: BinaryOp ( ..) |
1053- mir:: Rvalue :: CheckedBinaryOp ( ..) |
10541060 mir:: Rvalue :: UnaryOp ( ..) |
10551061 mir:: Rvalue :: Discriminant ( ..) |
10561062 mir:: Rvalue :: NullaryOp ( ..) |
0 commit comments