Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i8::MIN / -1 panics but verifies #1155

Closed
ambiso opened this issue Dec 2, 2024 · 3 comments · Fixed by #1166
Closed

i8::MIN / -1 panics but verifies #1155

ambiso opened this issue Dec 2, 2024 · 3 comments · Fixed by #1166

Comments

@ambiso
Copy link

ambiso commented Dec 2, 2024

The following function verifies with the condition that y != 0, but I believe it should not, since it can panic.

// Read more about `requires` here: https://hacspec.org/book/tutorial/panic-freedom.html
#[hax_lib::requires(y != 0)]
fn d(x: i8, y: i8) -> i8 {
    x / y
}

Open this code snippet in the playground

When calling this function with i8::MIN and -1 it overflows:

fn d(x: i8, y: i8) -> i8 {
    x / y
}

fn main() {
    println!("{}", d(i8::MIN, -1));
}
$ cargo run
   Compiling hax_repro v0.1.0 (/home/projects/dump/hax_repro)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/hax_repro`
thread 'main' panicked at src/main.rs:2:5:
attempt to divide with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

(See also https://blog.regehr.org/archives/887 and https://mastodon.social/@regehr/113564124872096630 )

@ambiso
Copy link
Author

ambiso commented Dec 2, 2024

More direct repro:

#[allow(unconditional_panic)]

// Read more about `requires` here: https://hacspec.org/book/tutorial/panic-freedom.html
#[hax_lib::requires(true)]
fn d() -> i8 {
    (-128i8) / (-1i8)
}

Playground

@ambiso
Copy link
Author

ambiso commented Dec 2, 2024

I assume this condition would need to be updated?

let div (#t:inttype) (a:int_t t) (b:int_t t{v b <> 0}) =

It seems odd that the instantiation of the int succeeds when the resulting integer is out of bounds

Is this assume at fault?

assume(unsigned t \/ range (v a / v b) t); // see issue #423

@karthikbhargavan
Copy link
Contributor

karthikbhargavan commented Dec 2, 2024 via email

@franziskuskiefer franziskuskiefer linked a pull request Dec 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants