rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.48k stars 12.73k forks source link

ICE: 'index out of bounds: the len is 1 but the index is 1' with Cdebuginfo=2 #105263

Open matthiaskrgr opened 1 year ago

matthiaskrgr commented 1 year ago

Code

code from official tests: ./src/test/ui/mir/ssa-analysis-regression-50041.rs

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

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

struct NonNull<T: ?Sized>(*const T);

struct Unique<T: ?Sized>(NonNull<T>);

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

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

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

#[inline(never)]
fn dealloc<T: ?Sized>(_: *const 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.67.0-nightly (234151769 2022-12-03)
binary: rustc
commit-hash: 23415176968e81e0aac92d0218612a89c4e68a82
commit-date: 2022-12-03
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

rustc ./src/test/ui/mir/ssa-analysis-regression-50041.rs -Cdebuginfo=2

<output>
Backtrace

``` thread '' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/23415176968e81e0aac92d0218612a89c4e68a82/compiler/rustc_middle/src/ty/subst.rs:387:43 stack backtrace: 0: 0x7f8d8936625a - std::backtrace_rs::backtrace::libunwind::trace::h39c51bcedb139b44 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f8d8936625a - std::backtrace_rs::backtrace::trace_unsynchronized::h9cf890f6f509d0c3 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f8d8936625a - std::sys_common::backtrace::_print_fmt::h4a0d7673c4689a86 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7f8d8936625a - ::fmt::hed99d8097fd95926 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f8d893c8e4e - core::fmt::write::hdab16ae0136a16af at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/core/src/fmt/mod.rs:1208:17 5: 0x7f8d89356675 - std::io::Write::write_fmt::h9619f0289bf5af21 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/io/mod.rs:1682:15 6: 0x7f8d89366025 - std::sys_common::backtrace::_print::h2fbe09348ca97657 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7f8d89366025 - std::sys_common::backtrace::print::h72058f5ceb813403 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7f8d89368d6f - std::panicking::default_hook::{{closure}}::h1542b395e584376b at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:267:22 9: 0x7f8d89368aab - std::panicking::default_hook::hf92492522bb6bc51 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:286:9 10: 0x7f8d8936958c - std::panicking::rust_panic_with_hook::h8e3ba576266d6126 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:688:13 11: 0x7f8d89369329 - std::panicking::begin_panic_handler::{{closure}}::h5718d689762256a1 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:579:13 12: 0x7f8d8936670c - std::sys_common::backtrace::__rust_end_short_backtrace::hb4469c61f2390e29 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:137:18 13: 0x7f8d89369032 - rust_begin_unwind at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:575:5 14: 0x7f8d893c5863 - core::panicking::panic_fmt::h4dafe9d2577d7060 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/core/src/panicking.rs:64:14 15: 0x7f8d893c5a32 - core::panicking::panic_bounds_check::hf370cb7cb7f7e64d at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/core/src/panicking.rs:147:5 16: 0x7f8d8ad7cbd6 - rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::type_di_node 17: 0x7f8d8ad98d44 - as core[ec9ef0a26f3cf28]::iter::traits::collect::Extend<&rustc_codegen_llvm[503052878b417ad6]::llvm_::ffi::Metadata>>::extend::>, alloc[c9a67e0c95f99b51]::vec::into_iter::IntoIter>, rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::build_generic_type_param_di_nodes::{closure#0}>> 18: 0x7f8d8ad80050 - rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::build_generic_type_param_di_nodes 19: 0x7f8d8ad8d6b5 - rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::type_map::build_type_with_children:: 20: 0x7f8d8ad8a297 - as core[ec9ef0a26f3cf28]::iter::traits::collect::Extend>::extend::, rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::enums::native::build_enum_type_di_node::{closure#0}::{closure#0}>> 21: 0x7f8d8ad88eb9 - rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::type_map::build_type_with_children:: fn(&'a rustc_codegen_llvm[503052878b417ad6]::context::CodegenCx<'b, 'c>) -> smallvec[70a3a4fd81953d85]::SmallVec<[&'b rustc_codegen_llvm[503052878b417ad6]::llvm_::ffi::Metadata; 16usize]>> 22: 0x7f8d8ad8565d - rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::enums::native::build_enum_type_di_node 23: 0x7f8d8ad84ccf - rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::enums::build_enum_type_di_node 24: 0x7f8d8ad7a634 - rustc_codegen_llvm[503052878b417ad6]::debuginfo::metadata::type_di_node 25: 0x7f8d8ad762f4 - ::dbg_scope_fn 26: 0x7f8d8a7af911 - rustc_codegen_ssa[6d1b86094529188b]::mir::codegen_mir:: 27: 0x7f8d8aed58d1 - rustc_codegen_llvm[503052878b417ad6]::base::compile_codegen_unit::module_codegen 28: 0x7f8d8bd702a3 - >::with_task::> 29: 0x7f8d8bd6ffba - rustc_codegen_llvm[503052878b417ad6]::base::compile_codegen_unit 30: 0x7f8d8bb34cee - rustc_codegen_ssa[6d1b86094529188b]::base::codegen_crate:: 31: 0x7f8d8bb3448e - ::codegen_crate 32: 0x7f8d8b84bdd1 - ::time::, rustc_interface[c57545daadc3fa09]::passes::start_codegen::{closure#0}> 33: 0x7f8d8b84b8c5 - rustc_interface[c57545daadc3fa09]::passes::start_codegen 34: 0x7f8d8b846fad - ::enter::<::ongoing_codegen::{closure#0}::{closure#0}, core[ec9ef0a26f3cf28]::result::Result, rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>> 35: 0x7f8d8b8447c4 - ::ongoing_codegen 36: 0x7f8d8b843991 - ::enter::, rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>> 37: 0x7f8d8b83e978 - rustc_span[653636119034ca50]::with_source_map::, rustc_interface[c57545daadc3fa09]::interface::run_compiler, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 38: 0x7f8d8b83e465 - >::set::, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>> 39: 0x7f8d8b83da52 - std[b988c8daa9554a2a]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>> 40: 0x7f8d8bfa6848 - <::spawn_unchecked_, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>::{closure#1} as core[ec9ef0a26f3cf28]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 41: 0x7f8d8d4b07f3 - as core::ops::function::FnOnce>::call_once::hd24e4095bea58fc3 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/alloc/src/boxed.rs:2000:9 42: 0x7f8d8d4b07f3 - as core::ops::function::FnOnce>::call_once::h7c7f47af88aff778 at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/alloc/src/boxed.rs:2000:9 43: 0x7f8d8d4b07f3 - std::sys::unix::thread::Thread::new::thread_start::h8d5de08b8b3f2cac at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys/unix/thread.rs:108:17 44: 0x7f8d890cc8fd - 45: 0x7f8d8914ea60 - 46: 0x0 - ```

matthiaskrgr commented 1 year ago

searched toolchains nightly-2022-03-05 through nightly-2022-12-04


Regression in nightly-2022-03-12


:thinking:

matthiaskrgr commented 1 year ago

I wonder if this is https://github.com/rust-lang/rust/pull/94728 cc @compiler-errors any ideas?

compiler-errors commented 1 year ago

so this is because it's an invalid definition of Box -- not sure if we want to support no_core + custom Box impl w/ only a T and no allocator A

matthiaskrgr commented 1 year ago

Since we have a test for this I would assume that this is expected to work? :sweat_smile:

compiler-errors commented 1 year ago

Well, this test wasn't modified after the allocator parameter was added to Box, so that's why. Not sure if it's intended to support this or not.

matthiaskrgr commented 1 year ago

hmm.

The original ticket was about some mir inlining/llvm problem apparently https://github.com/rust-lang/rust/issues/50041