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: the len is 1 but the index is 1: layout.rs #96175

Closed
matthiaskrgr opened this issue Apr 18, 2022 · 4 comments
Closed
Labels
A-lang-item Area: lang items C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

Code

// build-pass
// compile-flags: -Z mir-opt-level=3

#![crate_type="lib"]
#![feature(lang_items)]
#![no_std]

#[lang = "owned_box"]
pub struct Box<T: ?Sized>(*mut T);

impl<T: ?Sized> Drop for Box<T> {
    fn drop(&mut self) {
    }
}

#[lang = "box_free"]
#[inline(always)]
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
    dealloc(ptr)
}

#[inline(never)]
fn dealloc<T: ?Sized>(_: *mut T) {
}

pub struct Foo<T>(T);

pub fn foo(a: Option<Box<Foo<usize>>>) -> usize {
    let f = match a {
        None => Foo(0),
        Some(vec) => *vec,
    };
    f.0
}

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (ec77f2524 2022-04-17)
binary: rustc
commit-hash: ec77f252434a532fdb5699ae4f21a3072d211edd
commit-date: 2022-04-17
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.0

Error output

<output>
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/compiler/rustc_middle/src/ty/layout.rs:2408:51
stack backtrace:
   0:     0x7fa4c7c9d83d - std::backtrace_rs::backtrace::libunwind::trace::hdc1f21fb71c845ee
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fa4c7c9d83d - std::backtrace_rs::backtrace::trace_unsynchronized::h825695a1eac7e4dc
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa4c7c9d83d - std::sys_common::backtrace::_print_fmt::h201cc1fed0ce4598
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fa4c7c9d83d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4c86a2fdb08a33f9
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fa4c7cf8f1c - core::fmt::write::hee99b3f0c63f5ca9
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/core/src/fmt/mod.rs:1194:17
   5:     0x7fa4c7c8f031 - std::io::Write::write_fmt::hfa56cdeea03f4b89
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/io/mod.rs:1655:15
   6:     0x7fa4c7ca0555 - std::sys_common::backtrace::_print::hbd75018aef718598
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fa4c7ca0555 - std::sys_common::backtrace::print::hc594da4af1e8ead7
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fa4c7ca0555 - std::panicking::default_hook::{{closure}}::h0602100d469ef01e
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/panicking.rs:295:22
   9:     0x7fa4c7ca01c9 - std::panicking::default_hook::hc7ef6a8909090411
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/panicking.rs:314:9
  10:     0x7fa4c84d0521 - rustc_driver[8e3c698622bece67]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fa4c7ca0d26 - std::panicking::rust_panic_with_hook::hb9245fe7222caa6e
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/panicking.rs:702:17
  12:     0x7fa4c7ca0b27 - std::panicking::begin_panic_handler::{{closure}}::he83bcf9a0c850a85
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/panicking.rs:588:13
  13:     0x7fa4c7c9dcf4 - std::sys_common::backtrace::__rust_end_short_backtrace::h465a02e71d825eac
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7fa4c7ca0859 - rust_begin_unwind
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/panicking.rs:584:5
  15:     0x7fa4c7c65c33 - core::panicking::panic_fmt::h23e69d1ae62ab6cd
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/core/src/panicking.rs:142:14
  16:     0x7fa4c7c65b72 - core::panicking::panic_bounds_check::h8691db1ad4a2a4b5
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/core/src/panicking.rs:84:5
  17:     0x7fa4c97ce917 - <rustc_middle[c02e249562e6ab88]::ty::Ty as rustc_target[707938acfa23df7d]::abi::TyAbiInterface<_>>::ty_and_layout_field::field_ty_or_layout::<rustc_codegen_llvm[b528a78dcf849805]::context::CodegenCx>
  18:     0x7fa4c97e941f - <rustc_target[707938acfa23df7d]::abi::TyAndLayout<rustc_middle[c02e249562e6ab88]::ty::Ty>>::field::<rustc_codegen_llvm[b528a78dcf849805]::context::CodegenCx>
  19:     0x7fa4c981e8bb - <rustc_codegen_ssa[a235b737831fdbb2]::mir::FunctionCx<rustc_codegen_llvm[b528a78dcf849805]::builder::Builder>>::codegen_place
  20:     0x7fa4c9815481 - <rustc_codegen_ssa[a235b737831fdbb2]::mir::FunctionCx<rustc_codegen_llvm[b528a78dcf849805]::builder::Builder>>::codegen_rvalue
  21:     0x7fa4c97fbbf9 - rustc_codegen_ssa[a235b737831fdbb2]::mir::codegen_mir::<rustc_codegen_llvm[b528a78dcf849805]::builder::Builder>
  22:     0x7fa4c97c7503 - rustc_codegen_llvm[b528a78dcf849805]::base::compile_codegen_unit::module_codegen
  23:     0x7fa4ca594716 - <rustc_query_system[b98794630d07627]::dep_graph::graph::DepGraph<rustc_middle[c02e249562e6ab88]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[c02e249562e6ab88]::ty::context::TyCtxt, rustc_span[e15e523c5f5ffbde]::symbol::Symbol, rustc_codegen_ssa[a235b737831fdbb2]::ModuleCodegen<rustc_codegen_llvm[b528a78dcf849805]::ModuleLlvm>>
  24:     0x7fa4ca5941f9 - rustc_codegen_llvm[b528a78dcf849805]::base::compile_codegen_unit
  25:     0x7fa4ca565f35 - rustc_codegen_ssa[a235b737831fdbb2]::base::codegen_crate::<rustc_codegen_llvm[b528a78dcf849805]::LlvmCodegenBackend>
  26:     0x7fa4ca5b90fe - <rustc_codegen_llvm[b528a78dcf849805]::LlvmCodegenBackend as rustc_codegen_ssa[a235b737831fdbb2]::traits::backend::CodegenBackend>::codegen_crate
  27:     0x7fa4ca540327 - <rustc_session[8619e56cac793b58]::session::Session>::time::<alloc[8d468ea801fd4f9]::boxed::Box<dyn core[f08f6a517a2b1407]::any::Any>, rustc_interface[b4fe925d1e8786a0]::passes::start_codegen::{closure#0}>
  28:     0x7fa4ca53c0ec - <rustc_interface[b4fe925d1e8786a0]::passes::QueryContext>::enter::<<rustc_interface[b4fe925d1e8786a0]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[f08f6a517a2b1407]::result::Result<alloc[8d468ea801fd4f9]::boxed::Box<dyn core[f08f6a517a2b1407]::any::Any>, rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>>
  29:     0x7fa4ca55e58f - <rustc_interface[b4fe925d1e8786a0]::queries::Queries>::ongoing_codegen
  30:     0x7fa4ca505dcb - <rustc_interface[b4fe925d1e8786a0]::interface::Compiler>::enter::<rustc_driver[8e3c698622bece67]::run_compiler::{closure#1}::{closure#2}, core[f08f6a517a2b1407]::result::Result<core[f08f6a517a2b1407]::option::Option<rustc_interface[b4fe925d1e8786a0]::queries::Linker>, rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>>
  31:     0x7fa4ca52eeef - rustc_span[e15e523c5f5ffbde]::with_source_map::<core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>, rustc_interface[b4fe925d1e8786a0]::interface::create_compiler_and_run<core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>, rustc_driver[8e3c698622bece67]::run_compiler::{closure#1}>::{closure#1}>
  32:     0x7fa4ca5069b7 - <scoped_tls[ed206aee8c9203a6]::ScopedKey<rustc_span[e15e523c5f5ffbde]::SessionGlobals>>::set::<rustc_interface[b4fe925d1e8786a0]::interface::run_compiler<core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>, rustc_driver[8e3c698622bece67]::run_compiler::{closure#1}>::{closure#0}, core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>>
  33:     0x7fa4ca51bf0f - std[7eb92d5d5059ff02]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b4fe925d1e8786a0]::util::run_in_thread_pool_with_globals<rustc_interface[b4fe925d1e8786a0]::interface::run_compiler<core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>, rustc_driver[8e3c698622bece67]::run_compiler::{closure#1}>::{closure#0}, core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>>::{closure#0}, core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>>
  34:     0x7fa4ca51c049 - <<std[7eb92d5d5059ff02]::thread::Builder>::spawn_unchecked_<rustc_interface[b4fe925d1e8786a0]::util::run_in_thread_pool_with_globals<rustc_interface[b4fe925d1e8786a0]::interface::run_compiler<core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>, rustc_driver[8e3c698622bece67]::run_compiler::{closure#1}>::{closure#0}, core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>>::{closure#0}, core[f08f6a517a2b1407]::result::Result<(), rustc_errors[dbef8fecc23abfce]::ErrorGuaranteed>>::{closure#1} as core[f08f6a517a2b1407]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7fa4c7caabd3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd2056160a42acd52
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/alloc/src/boxed.rs:1866:9
  36:     0x7fa4c7caabd3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h99c5b980edefbf69
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/alloc/src/boxed.rs:1866:9
  37:     0x7fa4c7caabd3 - std::sys::unix::thread::Thread::new::thread_start::h42961cfa146716e3
                               at /rustc/ec77f252434a532fdb5699ae4f21a3072d211edd/library/std/src/sys/unix/thread.rs:108:17
  38:     0x7fa4c7a835c2 - start_thread
  39:     0x7fa4c7b08584 - __clone
  40:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: 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.62.0-nightly (ec77f2524 2022-04-17) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@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 Apr 18, 2022
@asquared31415
Copy link
Contributor

asquared31415 commented Apr 19, 2022

@rustbot label +A-lang-item

@rustbot rustbot added the A-lang-item Area: lang items label Apr 19, 2022
@beepster4096
Copy link
Contributor

This is because some of the code related to dereferencing Box now assumes that Box contains a Unique field. You can prevent the ICE by adding a separate Unique struct or by putting the pointer into a tuple like (*mut T,).

@beepster4096
Copy link
Contributor

Actually you would need ((*mut T,),) because Unique has NonNull now and that is also assumed by the compiler. Would be more readable to copy over the Unique struct.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 23, 2022
@Noratrieb
Copy link
Member

Noratrieb commented Jan 30, 2023

Now errors with

error: internal compiler error: compiler/rustc_mir_transform/src/elaborate_box_derefs.rs:97:17: expected Box to contain Unique

This seems good and correct, modifying lang items like this is not supported.

@Noratrieb Noratrieb closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lang-item Area: lang items C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

No branches or pull requests

6 participants