Skip to content

Commit

Permalink
Auto merge of rust-lang#94512 - RalfJung:sdiv-ub, r=oli-obk
Browse files Browse the repository at this point in the history
Miri/CTFE: properly treat overflow in (signed) division/rem as UB

To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine.

r? `@oli-obk`
  • Loading branch information
bors committed Mar 3, 2022
2 parents 7f44a75 + c45a42a commit 92b6955
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/ui/modulo_one.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: this arithmetic operation will overflow
error: this operation will panic at runtime
--> $DIR/modulo_one.rs:11:5
|
LL | i32::MIN % (-1); // also caught by rustc
| ^^^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow
|
= note: `#[deny(arithmetic_overflow)]` on by default
= note: `#[deny(unconditional_panic)]` on by default

error: this arithmetic operation will overflow
error: this operation will panic at runtime
--> $DIR/modulo_one.rs:21:5
|
LL | INT_MIN % NEG_ONE; // also caught by rustc
| ^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow

error: this arithmetic operation will overflow
error: this operation will panic at runtime
--> $DIR/modulo_one.rs:22:5
|
LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc
Expand Down

0 comments on commit 92b6955

Please sign in to comment.