You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#![feature(core_intrinsics)]fnmain(){let ub = unsafe{unchecked_div(i32::MAX, -1)};// ---> Uncomment this line to see MIRI correctly finding the overflow.// let ub = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) };println!("{ub}");}unsafefnunchecked_div(a:i32,b:i32) -> i32{
std::intrinsics::unchecked_div(a, b)}
I expected to see this happen: MIRI should fail with the following error:
error: Undefined Behavior: overflow in signed division (dividing MIN by -1)
Instead, this happened: No UB is detected and the program prints -2147483647.
Meta
I ran this using playground. The version reported is:
0.1.0 (2023-06-18 2d0aa57)
The text was updated successfully, but these errors were encountered:
I'm confused. i32::MAX / -1 doesn't overflow, and Miri correctly does not report UB for the unchecked version. i32::MIN / -1 does overflow, and Miri correctly reports UB for the unchecked version.
--> src/main.rs:9:23
|
9 | let ub = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow in signed division (dividing MIN by -1)
|
I tried running MIRI in this code:
I expected to see this happen: MIRI should fail with the following error:
Instead, this happened: No UB is detected and the program prints
-2147483647
.Meta
I ran this using playground. The version reported is:
The text was updated successfully, but these errors were encountered: