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 from ZSTs not at the start of structs during codegen for unsizing coercions #97732

Closed
Kixiron opened this issue Jun 4, 2022 · 0 comments · Fixed by #97738
Closed

ICE from ZSTs not at the start of structs during codegen for unsizing coercions #97732

Kixiron opened this issue Jun 4, 2022 · 0 comments · Fixed by #97738
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

@Kixiron
Copy link
Member

Kixiron commented Jun 4, 2022

Code

#![feature(coerce_unsized)]

use std::ops::CoerceUnsized;

#[repr(C)]
pub struct BoxWithZstTail<T: ?Sized>(Box<T>, ());

impl<S: ?Sized, T: ?Sized> CoerceUnsized<BoxWithZstTail<T>> for BoxWithZstTail<S>
    where Box<S>: CoerceUnsized<Box<T>>
{}

pub fn noop_dyn_upcast_with_zst_tail(b: BoxWithZstTail<dyn Send + Sync>) -> BoxWithZstTail<dyn Send> {
    b
}

Meta

rustc --version --verbose:

rustc 1.63.0-nightly (ebbcbfc23 2022-05-27)
binary: rustc
commit-hash: ebbcbfc236ced21d5e6a92269edb704692ff26b8
commit-date: 2022-05-27
host: x86_64-pc-windows-msvc
release: 1.63.0-nightly
LLVM version: 14.0.4
Backtrace

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `0`', /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/compiler/rustc_codegen_ssa/src/base.rs:219:17
stack backtrace:
   0:     0x7f078e0bb24d - std::backtrace_rs::backtrace::libunwind::trace::h5ecf6d3c2f2dbed3
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f078e0bb24d - std::backtrace_rs::backtrace::trace_unsynchronized::h1f34ec78f43478d1
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f078e0bb24d - std::sys_common::backtrace::_print_fmt::h5eb133ec83ff86d3
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f078e0bb24d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc8814d47922b5f5b
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f078e116fec - core::fmt::write::h871772ca8ace1475
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/core/src/fmt/mod.rs:1196:17
   5:     0x7f078e0ac9e1 - std::io::Write::write_fmt::he514622e09de3df5
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/io/mod.rs:1654:15
   6:     0x7f078e0bdf35 - std::sys_common::backtrace::_print::hd629e2d6c07b6e79
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f078e0bdf35 - std::sys_common::backtrace::print::h6bddafb613b6308d
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f078e0bdf35 - std::panicking::default_hook::{{closure}}::hf8d6097c4866d273
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/panicking.rs:295:22
   9:     0x7f078e0bdc56 - std::panicking::default_hook::h44331fd67f31aee4
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/panicking.rs:314:9
  10:     0x7f078e8946b1 - rustc_driver[7b89ea061d8aedc7]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f078e0be60a - std::panicking::rust_panic_with_hook::h51126dbc27bfe5a6
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/panicking.rs:702:17
  12:     0x7f078e0be447 - std::panicking::begin_panic_handler::{{closure}}::ha0ed88016ebdcd1e
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/panicking.rs:588:13
  13:     0x7f078e0bb704 - std::sys_common::backtrace::__rust_end_short_backtrace::h05a84a7ce4d2e529
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7f078e0be179 - rust_begin_unwind
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/panicking.rs:584:5
  15:     0x7f078e083443 - core::panicking::panic_fmt::hc7f457b7c7e09a46
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/core/src/panicking.rs:142:14
  16:     0x7f078e113d98 - core::panicking::assert_failed_inner::hc6fe9441630b9e22
  17:     0x7f078e9a2d6c - core[c8091fc9dea0c6cf]::panicking::assert_failed::<u64, u64>
  18:     0x7f0790a8c3a5 - rustc_codegen_ssa[3777d9370248289c]::base::unsize_ptr::<rustc_codegen_llvm[7635d7a996797e4d]::builder::Builder>
  19:     0x7f078fc0fd37 - <rustc_codegen_ssa[3777d9370248289c]::mir::FunctionCx<rustc_codegen_llvm[7635d7a996797e4d]::builder::Builder>>::codegen_rvalue_operand
  20:     0x7f078fbf3dfc - rustc_codegen_ssa[3777d9370248289c]::mir::codegen_mir::<rustc_codegen_llvm[7635d7a996797e4d]::builder::Builder>
  21:     0x7f078fbaa9b3 - rustc_codegen_llvm[7635d7a996797e4d]::base::compile_codegen_unit::module_codegen
  22:     0x7f0790ab3e16 - <rustc_query_system[a1cbf340ec6d6f93]::dep_graph::graph::DepGraph<rustc_middle[c4bb946b42085c78]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[c4bb946b42085c78]::ty::context::TyCtxt, rustc_span[c774ced8c61a5d44]::symbol::Symbol, rustc_codegen_ssa[3777d9370248289c]::ModuleCodegen<rustc_codegen_llvm[7635d7a996797e4d]::ModuleLlvm>>
  23:     0x7f0790ab3929 - rustc_codegen_llvm[7635d7a996797e4d]::base::compile_codegen_unit
  24:     0x7f0790a9e38a - <rustc_codegen_llvm[7635d7a996797e4d]::LlvmCodegenBackend as rustc_codegen_ssa[3777d9370248289c]::traits::backend::CodegenBackend>::codegen_crate
  25:     0x7f0790a5aac7 - <rustc_session[d1b76e352c1a3b5b]::session::Session>::time::<alloc[6f618ff12e561101]::boxed::Box<dyn core[c8091fc9dea0c6cf]::any::Any>, rustc_interface[94703aee012e7483]::passes::start_codegen::{closure#0}>
  26:     0x7f0790a85c2a - <rustc_interface[94703aee012e7483]::passes::QueryContext>::enter::<<rustc_interface[94703aee012e7483]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[c8091fc9dea0c6cf]::result::Result<alloc[6f618ff12e561101]::boxed::Box<dyn core[c8091fc9dea0c6cf]::any::Any>, rustc_errors[ae611370a546922c]::ErrorGuaranteed>>
  27:     0x7f0790a79f0f - <rustc_interface[94703aee012e7483]::queries::Queries>::ongoing_codegen
  28:     0x7f0790a2e382 - <rustc_interface[94703aee012e7483]::interface::Compiler>::enter::<rustc_driver[7b89ea061d8aedc7]::run_compiler::{closure#1}::{closure#2}, core[c8091fc9dea0c6cf]::result::Result<core[c8091fc9dea0c6cf]::option::Option<rustc_interface[94703aee012e7483]::queries::Linker>, rustc_errors[ae611370a546922c]::ErrorGuaranteed>>
  29:     0x7f0790a57d3f - rustc_span[c774ced8c61a5d44]::with_source_map::<core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>, rustc_interface[94703aee012e7483]::interface::create_compiler_and_run<core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>, rustc_driver[7b89ea061d8aedc7]::run_compiler::{closure#1}>::{closure#1}>
  30:     0x7f0790a2f1e2 - <scoped_tls[a35f89285f520bf3]::ScopedKey<rustc_span[c774ced8c61a5d44]::SessionGlobals>>::set::<rustc_interface[94703aee012e7483]::interface::run_compiler<core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>, rustc_driver[7b89ea061d8aedc7]::run_compiler::{closure#1}>::{closure#0}, core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>>
  31:     0x7f0790a4493f - std[f19dd7bb03296d5c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[94703aee012e7483]::util::run_in_thread_pool_with_globals<rustc_interface[94703aee012e7483]::interface::run_compiler<core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>, rustc_driver[7b89ea061d8aedc7]::run_compiler::{closure#1}>::{closure#0}, core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>>::{closure#0}, core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>>
  32:     0x7f0790a44a99 - <<std[f19dd7bb03296d5c]::thread::Builder>::spawn_unchecked_<rustc_interface[94703aee012e7483]::util::run_in_thread_pool_with_globals<rustc_interface[94703aee012e7483]::interface::run_compiler<core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>, rustc_driver[7b89ea061d8aedc7]::run_compiler::{closure#1}>::{closure#0}, core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>>::{closure#0}, core[c8091fc9dea0c6cf]::result::Result<(), rustc_errors[ae611370a546922c]::ErrorGuaranteed>>::{closure#1} as core[c8091fc9dea0c6cf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f078e0c8533 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb3d14b8461bee867
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/alloc/src/boxed.rs:1951:9
  34:     0x7f078e0c8533 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h528c1f598bc32c8b
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/alloc/src/boxed.rs:1951:9
  35:     0x7f078e0c8533 - std::sys::unix::thread::Thread::new::thread_start::h9efddab2b9d9a6d4
                               at /rustc/a6b8c6954829669a5c4fa320c3e6132edf04fcfc/library/std/src/sys/unix/thread.rs:108:17
  36:     0x7f078dfee609 - start_thread
  37:     0x7f078df11133 - clone
  38:                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.63.0-nightly (a6b8c6954 2022-06-03) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

@Kixiron Kixiron added 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. labels Jun 4, 2022
Kixiron added a commit to Kixiron/rust that referenced this issue Jun 4, 2022
@eddyb eddyb changed the title ICE from ZSTs not at the front of structs during codegen ICE from ZSTs not at the start of structs during codegen for unsizing coercions Jun 6, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 7, 2022
Fix ICEs from zsts within unsized types with non-zero offsets

- Fixes rust-lang#97732
- Fixes ICEs while compiling `alloc` with `-Z randomize-layout`

r? `@eddyb`
@bors bors closed this as completed in 62c260d Jun 7, 2022
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.

1 participant