Skip to content

Commit

Permalink
adjust for div/rem overflow being UB
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 3, 2022
1 parent 2b23786 commit 97ddcf1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/compile-fail/intrinsics/exact_div4.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(core_intrinsics)]
fn main() {
// divison of MIN by -1
unsafe { std::intrinsics::exact_div(i64::MIN, -1); } //~ ERROR result of dividing MIN by -1 cannot be represented
unsafe { std::intrinsics::exact_div(i64::MIN, -1); } //~ ERROR overflow in signed remainder (dividing MIN by -1)
}
2 changes: 1 addition & 1 deletion tests/compile-fail/intrinsics/unchecked_div1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(core_intrinsics)]
fn main() {
// MIN/-1 cannot be represented
unsafe { std::intrinsics::unchecked_div(i16::MIN, -1); } //~ ERROR overflow executing `unchecked_div`
unsafe { std::intrinsics::unchecked_div(i16::MIN, -1); } //~ ERROR overflow in signed division (dividing MIN by -1)
}
3 changes: 3 additions & 0 deletions tests/run-pass/integer-ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pub fn main() {
assert_eq!(100i8.wrapping_rem(10), 0);
assert_eq!((-128i8).wrapping_rem(-1), 0);

assert_eq!(i32::MIN.wrapping_div(-1), i32::MIN);
assert_eq!(i32::MIN.wrapping_rem(-1), 0);

assert_eq!(100i8.wrapping_neg(), -100);
assert_eq!((-128i8).wrapping_neg(), -128);

Expand Down

0 comments on commit 97ddcf1

Please sign in to comment.