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: You can't project to field 0 of DynMetadata because layout is weird and thinks it doesn't have fields. #125506

Closed
matthiaskrgr opened this issue May 24, 2024 · 2 comments · Fixed by #125508
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

auto-reduced (treereduce-rust):

#![feature(ptr_metadata)]

trait Foo {}

struct Bar;

impl Foo for Bar {}

fn main() {
    let a: *mut dyn Foo = &mut Bar;

    let d = a.to_raw_parts().0 as usize;
}

original:

// run-pass

#![feature(ptr_metadata)]

trait Foo {
    fn foo(&self) {}
}

struct Bar;

impl Foo for Bar {}

fn main() {
    // Test we can turn a fat pointer to array back into a thin pointer.
    let a: *const [i32] = &[1, 2, 3];
    let b = a as *const [i32; 2];
    unsafe {
        assert_eq!(*b, [1, 2]);
    }

    // Test conversion to an address (usize).
    let a: *const [i32; 3] = &[1, 2, 3];
    let b: *const [i32] = a;
    assert_eq!(a as usize, b as *const () as usize);

    // And conversion to a void pointer/address for trait objects too.
    let a: *mut dyn Foo = &mut Bar;
    let b = a as *mut () as usize;
    let c = a as *const () as usize;
    let d = a.to_raw_parts().0 as usize;

    assert_eq!(b, d);
    assert_eq!(c, d);
}

Version information

rustc 1.80.0-nightly (213ad10c8 2024-05-24)
binary: rustc
commit-hash: 213ad10c8f0fc275648552366275dc4e07f97462
commit-date: 2024-05-24
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Zvalidate-mir

Program output

warning: unused variable: `d`
  --> /tmp/icemaker_global_tempdir.MOmdI3aUIa6V/rustc_testrunner_tmpdir_reporting.HOhhbRhhlSye/mvce.rs:12:9
   |
12 |     let d = a.to_raw_parts().0 as usize;
   |         ^ help: if this is intentional, prefix it with an underscore: `_d`
   |
   = note: `#[warn(unused_variables)]` on by default

thread 'rustc' panicked at compiler/rustc_const_eval/src/transform/validate.rs:90:25:
broken MIR in Item(DefId(0:7 ~ mvce[a8d7]::main)) (after pass ScalarReplacementOfAggregates) at bb0[6]:
You can't project to field 0 of `DynMetadata` because layout is weird and thinks it doesn't have fields.
stack backtrace:
   0:     0x7d28bd152a15 - std::backtrace_rs::backtrace::libunwind::trace::ha14a3c487f1e072b
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7d28bd152a15 - std::backtrace_rs::backtrace::trace_unsynchronized::hf4889a75ccd505ee
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7d28bd152a15 - std::sys_common::backtrace::_print_fmt::h9590c8d63b078677
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7d28bd152a15 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd126fab93aa88efe
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7d28bd1a1aeb - core::fmt::rt::Argument::fmt::hf17f29f90df880a1
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/core/src/fmt/rt.rs:165:63
   5:     0x7d28bd1a1aeb - core::fmt::write::h0ebd95f36610e669
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/core/src/fmt/mod.rs:1172:21
   6:     0x7d28bd14776f - std::io::Write::write_fmt::h3eef362c47ded0c4
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/io/mod.rs:1835:15
   7:     0x7d28bd1527ee - std::sys_common::backtrace::_print::h6ff81878b57bf5c8
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7d28bd1527ee - std::sys_common::backtrace::print::hdc5e68f22314f4a9
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7d28bd155219 - std::panicking::default_hook::{{closure}}::h03d46e664671b447
  10:     0x7d28bd154fba - std::panicking::default_hook::h1ae40dc0fea72a33
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/panicking.rs:298:9
  11:     0x7d28b9b1709f - std[b9bb1320dc5ae1a4]::panicking::update_hook::<alloc[b0def3f22af53808]::boxed::Box<rustc_driver_impl[9effea81b954d024]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7d28bd15594b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h00416b40e105786e
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/alloc/src/boxed.rs:2077:9
  13:     0x7d28bd15594b - std::panicking::rust_panic_with_hook::h7af4ff1dc1e8071b
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/panicking.rs:799:13
  14:     0x7d28bd1556c4 - std::panicking::begin_panic_handler::{{closure}}::heb4d90acdc12b443
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/panicking.rs:664:13
  15:     0x7d28bd152ed9 - std::sys_common::backtrace::__rust_end_short_backtrace::h533bec95ab2736b2
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7d28bd1553f7 - rust_begin_unwind
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/panicking.rs:652:5
  17:     0x7d28bd19e0b3 - core::panicking::panic_fmt::h71bc10306699fad0
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/core/src/panicking.rs:72:14
  18:     0x7d28b8ed02b9 - <rustc_const_eval[9b69744695b0afef]::transform::validate::CfgChecker>::fail::<alloc[b0def3f22af53808]::string::String>
  19:     0x7d28b8ecef04 - <rustc_const_eval[9b69744695b0afef]::transform::validate::Validator as rustc_middle[c8c87ebb1fd33f9c]::mir::MirPass>::run_pass
  20:     0x7d28b9546940 - rustc_mir_transform[250cc2f4a89ad9b0]::pass_manager::validate_body
  21:     0x7d28bae01d45 - rustc_mir_transform[250cc2f4a89ad9b0]::pass_manager::run_passes_inner
  22:     0x7d28bb914b26 - rustc_mir_transform[250cc2f4a89ad9b0]::optimized_mir
  23:     0x7d28bb913c6b - rustc_query_impl[91ea4ef0d9b42432]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[91ea4ef0d9b42432]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c8c87ebb1fd33f9c]::query::erase::Erased<[u8; 8usize]>>
  24:     0x7d28baf91da7 - rustc_query_system[442df03e8028498c]::query::plumbing::try_execute_query::<rustc_query_impl[91ea4ef0d9b42432]::DynamicConfig<rustc_query_system[442df03e8028498c]::query::caches::DefIdCache<rustc_middle[c8c87ebb1fd33f9c]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[91ea4ef0d9b42432]::plumbing::QueryCtxt, false>
  25:     0x7d28baf915a0 - rustc_query_impl[91ea4ef0d9b42432]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7d28baf995b7 - <rustc_middle[c8c87ebb1fd33f9c]::ty::context::TyCtxt>::instance_mir
  27:     0x7d28bbb8e29a - rustc_monomorphize[5c6307a2377ff607]::collector::collect_items_rec::{closure#0}
  28:     0x7d28baf6208d - rustc_monomorphize[5c6307a2377ff607]::collector::collect_items_rec
  29:     0x7d28bb1cb391 - rustc_monomorphize[5c6307a2377ff607]::partitioning::collect_and_partition_mono_items
  30:     0x7d28bb1ca9d6 - rustc_query_impl[91ea4ef0d9b42432]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[91ea4ef0d9b42432]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c8c87ebb1fd33f9c]::query::erase::Erased<[u8; 24usize]>>
  31:     0x7d28bb1ca9a9 - <rustc_query_impl[91ea4ef0d9b42432]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[a480ab4ddb292070]::ops::function::FnOnce<(rustc_middle[c8c87ebb1fd33f9c]::ty::context::TyCtxt, ())>>::call_once
  32:     0x7d28bbc70fc8 - rustc_query_system[442df03e8028498c]::query::plumbing::try_execute_query::<rustc_query_impl[91ea4ef0d9b42432]::DynamicConfig<rustc_query_system[442df03e8028498c]::query::caches::SingleCache<rustc_middle[c8c87ebb1fd33f9c]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[91ea4ef0d9b42432]::plumbing::QueryCtxt, false>
  33:     0x7d28bbc70ce1 - rustc_query_impl[91ea4ef0d9b42432]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7d28bbc35c94 - rustc_codegen_ssa[786e474d3d8fe57a]::base::codegen_crate::<rustc_codegen_llvm[b358019a521b9791]::LlvmCodegenBackend>
  35:     0x7d28bbc296cc - <rustc_codegen_llvm[b358019a521b9791]::LlvmCodegenBackend as rustc_codegen_ssa[786e474d3d8fe57a]::traits::backend::CodegenBackend>::codegen_crate
  36:     0x7d28bbc2905f - rustc_interface[90b491fb83b45114]::passes::start_codegen
  37:     0x7d28bbc286da - <rustc_interface[90b491fb83b45114]::queries::Queries>::codegen_and_build_linker
  38:     0x7d28bb9c19ee - rustc_interface[90b491fb83b45114]::interface::run_compiler::<core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>, rustc_driver_impl[9effea81b954d024]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7d28bb9b5fe7 - std[b9bb1320dc5ae1a4]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[90b491fb83b45114]::util::run_in_thread_with_globals<rustc_interface[90b491fb83b45114]::util::run_in_thread_pool_with_globals<rustc_interface[90b491fb83b45114]::interface::run_compiler<core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>, rustc_driver_impl[9effea81b954d024]::run_compiler::{closure#0}>::{closure#1}, core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>>::{closure#0}, core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>>
  40:     0x7d28bb9b5daa - <<std[b9bb1320dc5ae1a4]::thread::Builder>::spawn_unchecked_<rustc_interface[90b491fb83b45114]::util::run_in_thread_with_globals<rustc_interface[90b491fb83b45114]::util::run_in_thread_pool_with_globals<rustc_interface[90b491fb83b45114]::interface::run_compiler<core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>, rustc_driver_impl[9effea81b954d024]::run_compiler::{closure#0}>::{closure#1}, core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>>::{closure#0}, core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a480ab4ddb292070]::result::Result<(), rustc_span[c256c11c98aa3170]::ErrorGuaranteed>>::{closure#2} as core[a480ab4ddb292070]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7d28bd15f72b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h89a54a9f8510c705
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/alloc/src/boxed.rs:2063:9
  42:     0x7d28bd15f72b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h195cf2ba72e01fdb
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/alloc/src/boxed.rs:2063:9
  43:     0x7d28bd15f72b - std::sys::pal::unix::thread::Thread::new::thread_start::h98d3876c0f9ad401
                               at /rustc/213ad10c8f0fc275648552366275dc4e07f97462/library/std/src/sys/pal/unix/thread.rs:108:17
  44:     0x7d28bcefd1cf - <unknown>
  45:     0x7d28bcf7e6ec - <unknown>
  46:                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: please make sure that you have updated to the latest nightly

note: rustc 1.80.0-nightly (213ad10c8 2024-05-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z validate-mir -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
warning: 1 warning emitted


@rustbot label +F-ptr_metadata

@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 May 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 24, 2024
@matthiaskrgr
Copy link
Member Author

#125479 cc @scottmcm

@scottmcm
Copy link
Member

Thanks!

I have a fix for this in #124251 -- I didn't know it was possible without that change. I'll pull it out to a separate PR.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 25, 2024
fmease added a commit to fmease/rust that referenced this issue May 26, 2024
jhpratt added a commit to jhpratt/rust that referenced this issue May 26, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 26, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 26, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 26, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue May 26, 2024
@bors bors closed this as completed in 5fef6c5 May 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 26, 2024
Rollup merge of rust-lang#125508 - scottmcm:fix-125506, r=Nilstrieb

Stop SRoA'ing `DynMetadata` in MIR

Fixes rust-lang#125506
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 26, 2024
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.

4 participants