Skip to content

MIRI fails to detect overflow in signed division #112864

Closed
@celinval

Description

@celinval

I tried running MIRI in this code:

#![feature(core_intrinsics)]
fn main() {
    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}");
}

unsafe fn unchecked_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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-miriArea: The miri toolC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions