Auto merge of #1992 - RalfJung:sdiv, r=RalfJung

adjust for div/rem overflow being UB

This is the Miri side of https://github.com/rust-lang/rust/pull/94512. Just some error messages change.
This commit is contained in:
bors 2022-03-03 17:32:59 +00:00
commit 2f9ecdeba4
5 changed files with 21 additions and 3 deletions

View File

@ -1 +1 @@
f0c4da49983aa699f715caf681e3154b445fb60b
45660949132222ba7ec0905649b2affd68e0e13c

View File

@ -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)
}

View File

@ -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
} }

View File

@ -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)
}

View File

@ -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);