diff options
| author | Ralf Jung <post@ralfj.de> | 2022-03-01 20:02:59 -0500 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-03-01 20:39:51 -0500 |
| commit | 6739299d18a16851140bc6b24b8eeae31e3d5878 (patch) | |
| tree | 03a1d2f6a86748a6bc5c7811fb6c8de4664c8785 /compiler/rustc_middle/src/mir | |
| parent | f0c4da49983aa699f715caf681e3154b445fb60b (diff) | |
| download | rust-6739299d18a16851140bc6b24b8eeae31e3d5878.tar.gz rust-6739299d18a16851140bc6b24b8eeae31e3d5878.zip | |
Miri/CTFE: properly treat overflow in (signed) division/rem as UB
Diffstat (limited to 'compiler/rustc_middle/src/mir')
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/error.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 31468ce73bf..389d31ea0c4 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -233,6 +233,10 @@ pub enum UndefinedBehaviorInfo<'tcx> { DivisionByZero, /// Something was "remainded" by 0 (x % 0). RemainderByZero, + /// Signed division overflowed (INT_MIN / -1). + DivisionOverflow, + /// Signed remainder overflowed (INT_MIN % -1). + RemainderOverflow, /// Overflowing inbounds pointer arithmetic. PointerArithOverflow, /// Invalid metadata in a wide pointer (using `str` to avoid allocations). @@ -310,6 +314,8 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> { } DivisionByZero => write!(f, "dividing by zero"), RemainderByZero => write!(f, "calculating the remainder with a divisor of zero"), + DivisionOverflow => write!(f, "overflow in signed division (dividing MIN by -1)"), + RemainderOverflow => write!(f, "overflow in signed remainder (dividing MIN by -1)"), PointerArithOverflow => write!(f, "overflowing in-bounds pointer arithmetic"), InvalidMeta(msg) => write!(f, "invalid metadata in wide pointer: {}", msg), InvalidVtableDropFn(sig) => write!( |
