Tweak implementation of overflow checking assertions
Extract and reuse logic controlling behaviour of overflow checking assertions instead of duplicating it three times.
This commit is contained in:
parent
e386217dd9
commit
27b430bcb3
7 changed files with 19 additions and 41 deletions
|
@ -1274,6 +1274,13 @@ impl<'tcx> BasicBlockData<'tcx> {
|
|||
}
|
||||
|
||||
impl<O> AssertKind<O> {
|
||||
/// Returns true if this an overflow checking assertion controlled by -C overflow-checks.
|
||||
pub fn is_optional_overflow_check(&self) -> bool {
|
||||
use AssertKind::*;
|
||||
use BinOp::*;
|
||||
matches!(self, OverflowNeg(..) | Overflow(Add | Sub | Mul | Shl | Shr, ..))
|
||||
}
|
||||
|
||||
/// Getting a description does not require `O` to be printable, and does not
|
||||
/// require allocation.
|
||||
/// The caller is expected to handle `BoundsCheck` separately.
|
||||
|
@ -1998,16 +2005,6 @@ impl BorrowKind {
|
|||
}
|
||||
}
|
||||
|
||||
impl BinOp {
|
||||
/// The checkable operators are those whose overflow checking behavior is controlled by
|
||||
/// -Coverflow-checks option. The remaining operators have either no overflow conditions (e.g.,
|
||||
/// BitAnd, BitOr, BitXor) or are always checked for overflow (e.g., Div, Rem).
|
||||
pub fn is_checkable(self) -> bool {
|
||||
use self::BinOp::*;
|
||||
matches!(self, Add | Sub | Mul | Shl | Shr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Debug for Rvalue<'tcx> {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
use self::Rvalue::*;
|
||||
|
|
|
@ -646,8 +646,7 @@ pub enum TerminatorKind<'tcx> {
|
|||
/// When overflow checking is disabled and this is run-time MIR (as opposed to compile-time MIR
|
||||
/// that is used for CTFE), the following variants of this terminator behave as `goto target`:
|
||||
/// - `OverflowNeg(..)`,
|
||||
/// - `Overflow(op, ..)` if op is a "checkable" operation (add, sub, mul, shl, shr, but NOT
|
||||
/// div or rem).
|
||||
/// - `Overflow(op, ..)` if op is add, sub, mul, shl, shr, but NOT div or rem.
|
||||
Assert {
|
||||
cond: Operand<'tcx>,
|
||||
expected: bool,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue