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

"Built-in" panics (e.g. OOB array access) cannot be caught #1070

Closed
RalfJung opened this issue Nov 22, 2019 · 1 comment · Fixed by #1084
Closed

"Built-in" panics (e.g. OOB array access) cannot be caught #1070

RalfJung opened this issue Nov 22, 2019 · 1 comment · Fixed by #1084
Labels
A-panics Area: affects panics and unwinding C-bug Category: This is a bug.

Comments

@RalfJung
Copy link
Member

The following code behaves wrong in Miri:

#![allow(const_err)]
use std::panic::catch_unwind;

fn main() {
    catch_unwind(|| [0, 1][2]).unwrap_err();
    println!("after-catch");
}

Instead of catching the panic, we get

error: Miri evaluation error: index out of bounds: the len is 2 but the index is 2
 --> t.rs:5:21
  |
5 |     catch_unwind(|| [0, 1][2]).unwrap_err();
  |                     ^^^^^^^^^ Miri evaluation error: index out of bounds: the len is 2 but the index is 2
  |
  = note: inside call to closure at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/panicking.rs:287:40
  = note: inside call to `std::panicking::try::do_call::<[closure@t.rs:5:18: 5:30], i32>` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/panicking.rs:282:5
  = note: inside call to `std::panicking::try::<i32, [closure@t.rs:5:18: 5:30]>` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/panic.rs:395:9
note: inside call to `std::panic::catch_unwind::<[closure@t.rs:5:18: 5:30], i32>` at t.rs:5:5
 --> t.rs:5:5
  |
5 |     catch_unwind(|| [0, 1][2]).unwrap_err();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: inside call to `main` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/rt.rs:61:34

Cc @Aaron1011

@RalfJung RalfJung added C-bug Category: This is a bug. A-panics Area: affects panics and unwinding labels Nov 22, 2019
@RalfJung
Copy link
Member Author

To match codegen, this should likely invoke the panic and panic_bounds_check lang items.

bors added a commit to rust-lang/rust that referenced this issue Dec 2, 2019
Miri engine: proper support for `Assert` MIR terminators

This puts down the basis for rust-lang/miri#1070, and I also did some clean-up. The Miri side of this is at rust-lang/miri#1084.

r? @oli-obk
bors added a commit that referenced this issue Dec 2, 2019
proper support for `Assert` MIR terminators

Fixes #1070
Blocked on rust-lang/rust#66874
@bors bors closed this as completed in 913226a Dec 2, 2019
@bors bors closed this as completed in #1084 Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-panics Area: affects panics and unwinding C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant