@@ -527,6 +527,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
527
527
let ( _res, overflow, _ty) = this. ecx . overflowing_unary_op ( op, val) ?;
528
528
Ok ( overflow)
529
529
} ) ? {
530
+ // `AssertKind` only has an `OverflowNeg` variant, to make sure that is
531
+ // appropriate to use.
530
532
assert_eq ! ( op, UnOp :: Neg , "Neg is the only UnOp that can overflow" ) ;
531
533
self . report_panic_as_lint ( source_info, PanicInfo :: OverflowNeg ) ?;
532
534
}
@@ -544,6 +546,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
544
546
) -> Option < ( ) > {
545
547
let r =
546
548
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.
547
550
if op == BinOp :: Shr || op == BinOp :: Shl {
548
551
let left_bits = place_layout. size . bits ( ) ;
549
552
let right_size = r. layout . size ;
@@ -564,7 +567,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
564
567
}
565
568
566
569
// The remaining operators are handled through `overflowing_binary_op`.
567
- // FIXME: Why do we not also do this for `Shr` and `Shl`?
568
570
if self . use_ecx ( |this| {
569
571
let l = this. ecx . read_immediate ( this. ecx . eval_operand ( left, None ) ?) ?;
570
572
let ( _res, overflow, _ty) = this. ecx . overflowing_binary_op ( op, l, r) ?;
@@ -603,16 +605,18 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
603
605
// 2. Working around bugs in other parts of the compiler
604
606
// - In this case, we'll return `None` from this function to stop evaluation.
605
607
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 .
609
611
Rvalue :: UnaryOp ( op, arg) if !overflow_check => {
610
612
trace ! ( "checking UnaryOp(op = {:?}, arg = {:?})" , op, arg) ;
611
613
self . check_unary_op ( * op, arg, source_info) ?;
612
614
}
613
615
614
616
// Additional checking: check for overflows on integer binary operations and report
615
617
// 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.
616
620
Rvalue :: BinaryOp ( op, left, right) if !overflow_check => {
617
621
trace ! ( "checking BinaryOp(op = {:?}, left = {:?}, right = {:?})" , op, left, right) ;
618
622
self . check_binary_op ( * op, left, right, source_info, place_layout) ?;
0 commit comments