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

ICE: index out of bounds, usefulness #117033

Closed
matthiaskrgr opened this issue Oct 21, 2023 · 3 comments · Fixed by #117034
Closed

ICE: index out of bounds, usefulness #117033

matthiaskrgr opened this issue Oct 21, 2023 · 3 comments · Fixed by #117034
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

File: /tmp/icemaker/72181.rs

auto-reduced (treereduce-rust):

enum Void {}

fn f(v: Void) -> ! {
    match v {}
}

fn main() {
    let v: Void = unsafe { std::mem::transmute::<(), Void>(()) };
    f(v);
}

original:

#![feature(never_type)]
#![allow(unused, invalid_value)]

enum Void {}

fn f(v: Void) -> ! {
    match v {} //~ ERROR entering unreachable code
}

fn main() {
    let v: Void = unsafe {
        std::mem::transmute::<(), Void>(())
    };
    f(v); //~ inside `main`
}

Version information

rustc 1.75.0-nightly (0d1664674 2023-10-21)
binary: rustc
commit-hash: 0d1664674a620f2c139be756a5cf7b1b057bc3a9
commit-date: 2023-10-21
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(non_exhaustive_omitted_patterns_lint) -Wnon-exhaustive-omitted-patterns

Program output

thread 'rustc' panicked at compiler/rustc_mir_build/src/thir/pattern/usefulness.rs:887:14:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x7fc926b6917c - std::backtrace_rs::backtrace::libunwind::trace::h01509ae085fb8b11
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fc926b6917c - std::backtrace_rs::backtrace::trace_unsynchronized::h94ef5e8e8d5ea87b
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fc926b6917c - std::sys_common::backtrace::_print_fmt::h0b35ef2c05dde194
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fc926b6917c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h633341ea30a5f327
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fc926bcb400 - core::fmt::rt::Argument::fmt::hd3a92f1ce7a7db06
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/core/src/fmt/rt.rs:142:9
   5:     0x7fc926bcb400 - core::fmt::write::hf91d2aa8e4d084f5
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/core/src/fmt/mod.rs:1117:17
   6:     0x7fc926b5d09f - std::io::Write::write_fmt::he8307bc52a524c8e
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/io/mod.rs:1762:15
   7:     0x7fc926b68f64 - std::sys_common::backtrace::_print::h6c27a0d5bab96c5d
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fc926b68f64 - std::sys_common::backtrace::print::h8b89ce035b71d50c
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fc926b6bbf7 - std::panicking::default_hook::{{closure}}::h411a7c125ecb9d05
  10:     0x7fc926b6b95f - std::panicking::default_hook::h5d5fee123330a759
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/panicking.rs:292:9
  11:     0x7fc929681120 - std[f4efd563eee42cb1]::panicking::update_hook::<alloc[156d4197a6564500]::boxed::Box<rustc_driver_impl[9201c065c27ce5d7]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fc926b6c338 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hcb9e1bcc3d9dd556
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/alloc/src/boxed.rs:2021:9
  13:     0x7fc926b6c338 - std::panicking::rust_panic_with_hook::hb348c6f446da2573
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/panicking.rs:735:13
  14:     0x7fc926b6c08e - std::panicking::begin_panic_handler::{{closure}}::he247db6939c402b2
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/panicking.rs:609:13
  15:     0x7fc926b69646 - std::sys_common::backtrace::__rust_end_short_backtrace::h34bc29d5fc936ca6
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7fc926b6bdf2 - rust_begin_unwind
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/panicking.rs:597:5
  17:     0x7fc926bc7b25 - core::panicking::panic_fmt::h857b4f3a6374266e
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/core/src/panicking.rs:72:14
  18:     0x7fc926bc7d42 - core::panicking::panic_bounds_check::h86dc87e9f444db14
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/core/src/panicking.rs:190:5
  19:     0x7fc929b2a6a3 - rustc_mir_build[876fa77fc50d6d52]::thir::pattern::usefulness::collect_nonexhaustive_missing_variants
  20:     0x7fc92a933025 - rustc_mir_build[876fa77fc50d6d52]::thir::pattern::usefulness::compute_match_usefulness
  21:     0x7fc9279e2861 - <rustc_mir_build[876fa77fc50d6d52]::thir::pattern::check_match::MatchVisitor as rustc_middle[6630f2cd22fa884b]::thir::visit::Visitor>::visit_expr
  22:     0x7fc9279e1f49 - <rustc_mir_build[876fa77fc50d6d52]::thir::pattern::check_match::MatchVisitor as rustc_middle[6630f2cd22fa884b]::thir::visit::Visitor>::visit_expr
  23:     0x7fc9279e2b63 - <rustc_mir_build[876fa77fc50d6d52]::thir::pattern::check_match::MatchVisitor as rustc_middle[6630f2cd22fa884b]::thir::visit::Visitor>::visit_expr
  24:     0x7fc9279e1f49 - <rustc_mir_build[876fa77fc50d6d52]::thir::pattern::check_match::MatchVisitor as rustc_middle[6630f2cd22fa884b]::thir::visit::Visitor>::visit_expr
  25:     0x7fc92aac9d4a - rustc_mir_build[876fa77fc50d6d52]::thir::pattern::check_match::check_match
  26:     0x7fc92aac9ad7 - rustc_query_impl[bb0c43c41d880ee9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bb0c43c41d880ee9]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7fc92aac94eb - rustc_query_system[b579e6e1f865e2fd]::query::plumbing::try_execute_query::<rustc_query_impl[bb0c43c41d880ee9]::DynamicConfig<rustc_query_system[b579e6e1f865e2fd]::query::caches::VecCache<rustc_span[2e3f5238368c790a]::def_id::LocalDefId, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[bb0c43c41d880ee9]::plumbing::QueryCtxt, false>
  28:     0x7fc92aac929d - rustc_query_impl[bb0c43c41d880ee9]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7fc92ac1ece1 - rustc_mir_build[876fa77fc50d6d52]::build::mir_built
  30:     0x7fc92ac1eafb - rustc_query_impl[bb0c43c41d880ee9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>
  31:     0x7fc92a86beac - rustc_query_system[b579e6e1f865e2fd]::query::plumbing::try_execute_query::<rustc_query_impl[bb0c43c41d880ee9]::DynamicConfig<rustc_query_system[b579e6e1f865e2fd]::query::caches::VecCache<rustc_span[2e3f5238368c790a]::def_id::LocalDefId, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[bb0c43c41d880ee9]::plumbing::QueryCtxt, false>
  32:     0x7fc92a86b890 - rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7fc928a1972e - rustc_mir_transform[215800bab071105b]::check_unsafety::unsafety_check_result
  34:     0x7fc92a86bc87 - rustc_query_impl[bb0c43c41d880ee9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bb0c43c41d880ee9]::query_impl::unsafety_check_result::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7fc92a86beac - rustc_query_system[b579e6e1f865e2fd]::query::plumbing::try_execute_query::<rustc_query_impl[bb0c43c41d880ee9]::DynamicConfig<rustc_query_system[b579e6e1f865e2fd]::query::caches::VecCache<rustc_span[2e3f5238368c790a]::def_id::LocalDefId, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[bb0c43c41d880ee9]::plumbing::QueryCtxt, false>
  36:     0x7fc92a86b950 - rustc_query_impl[bb0c43c41d880ee9]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7fc92a86c99a - rustc_mir_transform[215800bab071105b]::mir_const
  38:     0x7fc92a86c8e7 - rustc_query_impl[bb0c43c41d880ee9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>
  39:     0x7fc92a86beac - rustc_query_system[b579e6e1f865e2fd]::query::plumbing::try_execute_query::<rustc_query_impl[bb0c43c41d880ee9]::DynamicConfig<rustc_query_system[b579e6e1f865e2fd]::query::caches::VecCache<rustc_span[2e3f5238368c790a]::def_id::LocalDefId, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[bb0c43c41d880ee9]::plumbing::QueryCtxt, false>
  40:     0x7fc92a86ba10 - rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_const::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7fc928cab933 - rustc_mir_transform[215800bab071105b]::mir_promoted
  42:     0x7fc92aaca452 - rustc_query_impl[bb0c43c41d880ee9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 16usize]>>
  43:     0x7fc92aaca6c0 - rustc_query_system[b579e6e1f865e2fd]::query::plumbing::try_execute_query::<rustc_query_impl[bb0c43c41d880ee9]::DynamicConfig<rustc_query_system[b579e6e1f865e2fd]::query::caches::VecCache<rustc_span[2e3f5238368c790a]::def_id::LocalDefId, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[bb0c43c41d880ee9]::plumbing::QueryCtxt, false>
  44:     0x7fc92aaca353 - rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7fc92b37d143 - rustc_borrowck[98db7719697c2280]::mir_borrowck
  46:     0x7fc92b37d0af - rustc_query_impl[bb0c43c41d880ee9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>
  47:     0x7fc92a86beac - rustc_query_system[b579e6e1f865e2fd]::query::plumbing::try_execute_query::<rustc_query_impl[bb0c43c41d880ee9]::DynamicConfig<rustc_query_system[b579e6e1f865e2fd]::query::caches::VecCache<rustc_span[2e3f5238368c790a]::def_id::LocalDefId, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[bb0c43c41d880ee9]::plumbing::QueryCtxt, false>
  48:     0x7fc92a86bad0 - rustc_query_impl[bb0c43c41d880ee9]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7fc92ac2d6ec - rustc_interface[950f30a8e42de681]::passes::analysis
  50:     0x7fc92ac2d021 - rustc_query_impl[bb0c43c41d880ee9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bb0c43c41d880ee9]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 1usize]>>
  51:     0x7fc92b0d58e6 - rustc_query_system[b579e6e1f865e2fd]::query::plumbing::try_execute_query::<rustc_query_impl[bb0c43c41d880ee9]::DynamicConfig<rustc_query_system[b579e6e1f865e2fd]::query::caches::SingleCache<rustc_middle[6630f2cd22fa884b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[bb0c43c41d880ee9]::plumbing::QueryCtxt, false>
  52:     0x7fc92b0d5715 - rustc_query_impl[bb0c43c41d880ee9]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  53:     0x7fc92b3397ea - std[f4efd563eee42cb1]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[950f30a8e42de681]::util::run_in_thread_with_globals<rustc_interface[950f30a8e42de681]::interface::run_compiler<core[398df516b6292ea0]::result::Result<(), rustc_span[2e3f5238368c790a]::ErrorGuaranteed>, rustc_driver_impl[9201c065c27ce5d7]::run_compiler::{closure#1}>::{closure#0}, core[398df516b6292ea0]::result::Result<(), rustc_span[2e3f5238368c790a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[398df516b6292ea0]::result::Result<(), rustc_span[2e3f5238368c790a]::ErrorGuaranteed>>
  54:     0x7fc92b338af3 - <<std[f4efd563eee42cb1]::thread::Builder>::spawn_unchecked_<rustc_interface[950f30a8e42de681]::util::run_in_thread_with_globals<rustc_interface[950f30a8e42de681]::interface::run_compiler<core[398df516b6292ea0]::result::Result<(), rustc_span[2e3f5238368c790a]::ErrorGuaranteed>, rustc_driver_impl[9201c065c27ce5d7]::run_compiler::{closure#1}>::{closure#0}, core[398df516b6292ea0]::result::Result<(), rustc_span[2e3f5238368c790a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[398df516b6292ea0]::result::Result<(), rustc_span[2e3f5238368c790a]::ErrorGuaranteed>>::{closure#1} as core[398df516b6292ea0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7fc926b77105 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0eb94936306cabe0
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/alloc/src/boxed.rs:2007:9
  56:     0x7fc926b77105 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h872f69967c8bfd56
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/alloc/src/boxed.rs:2007:9
  57:     0x7fc926b77105 - std::sys::unix::thread::Thread::new::thread_start::h137c6fabce8fb63e
                               at /rustc/0d1664674a620f2c139be756a5cf7b1b057bc3a9/library/std/src/sys/unix/thread.rs:108:17
  58:     0x7fc9269409eb - <unknown>
  59:     0x7fc9269c47cc - <unknown>
  60:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.75.0-nightly (0d1664674 2023-10-21) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(non_exhaustive_omitted_patterns_lint) -Z dump-mir-dir=dir

query stack during panic:
#0 [check_match] match-checking `f`
#1 [mir_built] building MIR for `f`
#2 [unsafety_check_result] unsafety-checking `f`
#3 [mir_const] preparing `f` for borrow checking
#4 [mir_promoted] promoting constants in MIR for `f`
#5 [mir_borrowck] borrow-checking `f`
#6 [analysis] running analysis passes on this crate
end of query stack
warning: unreachable expression
 --> /tmp/icemaker_global_tempdir.0Q5m6L1HMRcv/rustc_testrunner_tmpdir_reporting.M2meZgrJ4Cr3/mvce.rs:9:7
  |
8 |     let v: Void = unsafe { std::mem::transmute::<(), Void>(()) };
  |                            ----------------------------------- any code following this expression is unreachable
9 |     f(v);
  |       ^ unreachable expression
  |
note: this expression has type `Void`, which is uninhabited
 --> /tmp/icemaker_global_tempdir.0Q5m6L1HMRcv/rustc_testrunner_tmpdir_reporting.M2meZgrJ4Cr3/mvce.rs:8:28
  |
8 |     let v: Void = unsafe { std::mem::transmute::<(), Void>(()) };
  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: `#[warn(unreachable_code)]` on by default

warning: unused variable: `v`
 --> /tmp/icemaker_global_tempdir.0Q5m6L1HMRcv/rustc_testrunner_tmpdir_reporting.M2meZgrJ4Cr3/mvce.rs:8:9
  |
8 |     let v: Void = unsafe { std::mem::transmute::<(), Void>(()) };
  |         ^ help: if this is intentional, prefix it with an underscore: `_v`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 2 warnings emitted


@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Oct 21, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 21, 2023
@matthiaskrgr matthiaskrgr changed the title ICE: index out of bounds, usefullness ICE: index out of bounds, usefulness Oct 21, 2023
@albertlarsan68
Copy link
Member

What is intriguing is that the transmute doesn't fail, as it is a transmute from a 1ZST to a Never-like type, which has no representations.
This code is definitely unsound, but I guess this is already a known thing.

@matthiaskrgr
Copy link
Member Author

Regression in 786c94a
#116734 cc @Nadrieril

@Nadrieril
Copy link
Member

Nadrieril commented Oct 21, 2023

🤦 Oops, fix here: #117034. Good catch!

@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 21, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 22, 2023
Don't crash on empty match in the `nonexhaustive_omitted_patterns` lint

Oops

Fixes rust-lang#117033
@bors bors closed this as completed in a134f16 Oct 22, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 22, 2023
Rollup merge of rust-lang#117034 - Nadrieril:fix-117033, r=cjgillot

Don't crash on empty match in the `nonexhaustive_omitted_patterns` lint

Oops

Fixes rust-lang#117033
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants