@@ -527,6 +527,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
527527 let ( _res, overflow, _ty) = this. ecx . overflowing_unary_op ( op, val) ?;
528528 Ok ( overflow)
529529 } ) ? {
530+ // `AssertKind` only has an `OverflowNeg` variant, to make sure that is
531+ // appropriate to use.
530532 assert_eq ! ( op, UnOp :: Neg , "Neg is the only UnOp that can overflow" ) ;
531533 self . report_panic_as_lint ( source_info, PanicInfo :: OverflowNeg ) ?;
532534 }
@@ -544,6 +546,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
544546 ) -> Option < ( ) > {
545547 let r =
546548 self . use_ecx ( |this| this. ecx . read_immediate ( this. ecx . eval_operand ( right, None ) ?) ) ?;
549+ // Check for exceeding shifts *even if* we cannot evaluate the LHS.
547550 if op == BinOp :: Shr || op == BinOp :: Shl {
548551 let left_bits = place_layout. size . bits ( ) ;
549552 let right_size = r. layout . size ;
@@ -564,7 +567,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
564567 }
565568
566569 // The remaining operators are handled through `overflowing_binary_op`.
567- // FIXME: Why do we not also do this for `Shr` and `Shl`?
568570 if self . use_ecx ( |this| {
569571 let l = this. ecx . read_immediate ( this. ecx . eval_operand ( left, None ) ?) ?;
570572 let ( _res, overflow, _ty) = this. ecx . overflowing_binary_op ( op, l, r) ?;
@@ -603,16 +605,18 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
603605 // 2. Working around bugs in other parts of the compiler
604606 // - In this case, we'll return `None` from this function to stop evaluation.
605607 match rvalue {
606- // Additional checking: if overflow checks are disabled (which is usually the case in
607- // release mode), then we need to do additional checking here to give lints to the user
608- // if an overflow would occur .
608+ // Additional checking: give lints to the user if an overflow would occur.
609+ // If `overflow_check` is set, running const-prop on the `Assert` terminators
610+ // will already generate the appropriate messages .
609611 Rvalue :: UnaryOp ( op, arg) if !overflow_check => {
610612 trace ! ( "checking UnaryOp(op = {:?}, arg = {:?})" , op, arg) ;
611613 self . check_unary_op ( * op, arg, source_info) ?;
612614 }
613615
614616 // Additional checking: check for overflows on integer binary operations and report
615617 // them to the user as lints.
618+ // If `overflow_check` is set, running const-prop on the `Assert` terminators
619+ // will already generate the appropriate messages.
616620 Rvalue :: BinaryOp ( op, left, right) if !overflow_check => {
617621 trace ! ( "checking BinaryOp(op = {:?}, left = {:?}, right = {:?})" , op, left, right) ;
618622 self . check_binary_op ( * op, left, right, source_info, place_layout) ?;
0 commit comments