@@ -541,7 +541,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
541
541
right : & Operand < ' tcx > ,
542
542
source_info : SourceInfo ,
543
543
place_layout : TyLayout < ' tcx > ,
544
- overflow_check : bool ,
545
544
) -> Option < ( ) > {
546
545
let r =
547
546
self . use_ecx ( |this| this. ecx . read_immediate ( this. ecx . eval_operand ( right, None ) ?) ) ?;
@@ -564,18 +563,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
564
563
}
565
564
}
566
565
567
- // If overflow checking is enabled (like in debug mode by default),
568
- // then we'll already catch overflow when we evaluate the `Assert` statement
569
- // in MIR. However, if overflow checking is disabled, then there won't be any
570
- // `Assert` statement and so we have to do additional checking here.
571
- if !overflow_check {
572
- if self . use_ecx ( |this| {
573
- let l = this. ecx . read_immediate ( this. ecx . eval_operand ( left, None ) ?) ?;
574
- let ( _res, overflow, _ty) = this. ecx . overflowing_binary_op ( op, l, r) ?;
575
- Ok ( overflow)
576
- } ) ? {
577
- self . report_panic_as_lint ( source_info, PanicInfo :: Overflow ( op) ) ?;
578
- }
566
+ // The remaining operators are handled through `overflowing_binary_op`.
567
+ // FIXME: Why do we not also do this for `Shr` and `Shl`?
568
+ if self . use_ecx ( |this| {
569
+ let l = this. ecx . read_immediate ( this. ecx . eval_operand ( left, None ) ?) ?;
570
+ let ( _res, overflow, _ty) = this. ecx . overflowing_binary_op ( op, l, r) ?;
571
+ Ok ( overflow)
572
+ } ) ? {
573
+ self . report_panic_as_lint ( source_info, PanicInfo :: Overflow ( op) ) ?;
579
574
}
580
575
581
576
Some ( ( ) )
@@ -618,9 +613,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
618
613
619
614
// Additional checking: check for overflows on integer binary operations and report
620
615
// them to the user as lints.
621
- Rvalue :: BinaryOp ( op, left, right) => {
616
+ Rvalue :: BinaryOp ( op, left, right) if !overflow_check => {
622
617
trace ! ( "checking BinaryOp(op = {:?}, left = {:?}, right = {:?})" , op, left, right) ;
623
- self . check_binary_op ( * op, left, right, source_info, place_layout, overflow_check ) ?;
618
+ self . check_binary_op ( * op, left, right, source_info, place_layout) ?;
624
619
}
625
620
626
621
// Do not try creating references (#67862)
0 commit comments