Skip to content

Commit

Permalink
Auto merge of #1992 - RalfJung:sdiv, r=RalfJung
Browse files Browse the repository at this point in the history
adjust for div/rem overflow being UB

This is the Miri side of rust-lang/rust#94512. Just some error messages change.
  • Loading branch information
bors committed Mar 3, 2022
2 parents 2b23786 + c0f7251 commit 2f9ecde
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f0c4da49983aa699f715caf681e3154b445fb60b
45660949132222ba7ec0905649b2affd68e0e13c
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)
}
15 changes: 15 additions & 0 deletions tests/compile-fail/intrinsics/simd-div-overflow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(platform_intrinsics, repr_simd)]

extern "platform-intrinsic" {
pub(crate) fn simd_div<T>(x: T, y: T) -> T;
}

#[repr(simd)]
#[allow(non_camel_case_types)]
struct i32x2(i32, i32);

fn main() { unsafe {
let x = i32x2(1, i32::MIN);
let y = i32x2(1, -1);
simd_div(x, y); //~ERROR Undefined Behavior: overflow in signed division
} }
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 2f9ecde

Please sign in to comment.