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 when using offset_of with an unsized type #112051

Closed
tmiasko opened this issue May 28, 2023 · 0 comments · Fixed by #112069
Closed

ICE when using offset_of with an unsized type #112051

tmiasko opened this issue May 28, 2023 · 0 comments · Fixed by #112069
Labels
C-bug Category: This is a bug. F-offset_of `#![feature(offset_of)]` 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

@tmiasko
Copy link
Contributor

tmiasko commented May 28, 2023

Code

#![feature(offset_of)]
use std::fmt::Debug;
struct S<T: ?Sized> {
    a: u64,
    b: T,
}
fn main() {
    let x = core::mem::offset_of!(S<Box<()>>, a);
    let y = core::mem::offset_of!(S<dyn Debug>, a);
}

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (cca7ee581 2023-05-27)
binary: rustc
commit-hash: cca7ee58110726983951a19d5fb7316d9243925d
commit-date: 2023-05-27
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.4

Error output

thread 'rustc' panicked at 'assertion failed: bx.cx().type_is_sized(ty)', /rustc/cca7ee58110726983951a19d5fb7316d9243925d/compiler/rustc_codegen_ssa/src/mir/rvalue.rs:671:17
Backtrace

thread 'rustc' panicked at 'assertion failed: bx.cx().type_is_sized(ty)', /rustc/cca7ee58110726983951a19d5fb7316d9243925d/compiler/rustc_codegen_ssa/src/mir/rvalue.rs:671:17
stack backtrace:
   0:     0x7f61ea3698b1 - std::backtrace_rs::backtrace::libunwind::trace::h91704ec918f77c78
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f61ea3698b1 - std::backtrace_rs::backtrace::trace_unsynchronized::hd25690acb7e38be5
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f61ea3698b1 - std::sys_common::backtrace::_print_fmt::h146bb9a645668a5c
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f61ea3698b1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h06516363e7e12320
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f61ea3ca2ff - core::fmt::rt::Argument::fmt::h4d33ba7fbbbaa80b
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/core/src/fmt/rt.rs:138:9
   5:     0x7f61ea3ca2ff - core::fmt::write::h0c2495f04f0fd4f1
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f61ea35cab1 - std::io::Write::write_fmt::hb47ded088c57ebd2
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/io/mod.rs:1713:15
   7:     0x7f61ea3696c5 - std::sys_common::backtrace::_print::hbc8e99e0f4dc2dd4
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f61ea3696c5 - std::sys_common::backtrace::print::hf14b108899d6a9c5
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f61ea36c387 - std::panicking::default_hook::{{closure}}::hc1a53ebba49377ca
  10:     0x7f61ea36c174 - std::panicking::default_hook::ha7e07ec692015fe7
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/panicking.rs:288:9
  11:     0x7f61ed512efb - <rustc_driver_impl[9b9fd057b079c87d]::install_ice_hook::{closure#0} as core[dc0e626abd4c9e52]::ops::function::FnOnce<(&core[dc0e626abd4c9e52]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f61ea36cacd - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8242157725b18837
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/alloc/src/boxed.rs:1999:9
  13:     0x7f61ea36cacd - std::panicking::rust_panic_with_hook::h8c3d4fc60d33a402
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/panicking.rs:709:13
  14:     0x7f61ea36c821 - std::panicking::begin_panic_handler::{{closure}}::h9541d40caad03645
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/panicking.rs:595:13
  15:     0x7f61ea369ce6 - std::sys_common::backtrace::__rust_end_short_backtrace::h26bacb47f2917c74
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7f61ea36c5b2 - rust_begin_unwind
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/panicking.rs:593:5
  17:     0x7f61ea3c6583 - core::panicking::panic_fmt::h1d3026b296abc2d0
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/core/src/panicking.rs:67:14
  18:     0x7f61ea3c6613 - core::panicking::panic::hcf0146841de65acb
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/core/src/panicking.rs:117:5
  19:     0x7f61ebe6499b - <rustc_codegen_ssa[846eb25a9e917dd8]::mir::FunctionCx<rustc_codegen_llvm[8113e9edcdd0c14]::builder::Builder>>::codegen_rvalue_operand
  20:     0x7f61ebe35992 - rustc_codegen_ssa[846eb25a9e917dd8]::mir::codegen_mir::<rustc_codegen_llvm[8113e9edcdd0c14]::builder::Builder>
  21:     0x7f61ecb51c2b - rustc_codegen_llvm[8113e9edcdd0c14]::base::compile_codegen_unit::module_codegen
  22:     0x7f61ecb4f149 - <rustc_codegen_llvm[8113e9edcdd0c14]::LlvmCodegenBackend as rustc_codegen_ssa[846eb25a9e917dd8]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  23:     0x7f61ecb4caf7 - rustc_codegen_ssa[846eb25a9e917dd8]::base::codegen_crate::<rustc_codegen_llvm[8113e9edcdd0c14]::LlvmCodegenBackend>
  24:     0x7f61ecb4c3fb - <rustc_codegen_llvm[8113e9edcdd0c14]::LlvmCodegenBackend as rustc_codegen_ssa[846eb25a9e917dd8]::traits::backend::CodegenBackend>::codegen_crate
  25:     0x7f61ec79c402 - <rustc_session[7699662e81a4adee]::session::Session>::time::<alloc[cb0f54882c31da79]::boxed::Box<dyn core[dc0e626abd4c9e52]::any::Any>, rustc_interface[31484fcbe0571e9c]::passes::start_codegen::{closure#0}>
  26:     0x7f61ec79bf4b - rustc_interface[31484fcbe0571e9c]::passes::start_codegen
  27:     0x7f61ec79a05d - <rustc_middle[6a6e7583393ba8b2]::ty::context::GlobalCtxt>::enter::<<rustc_interface[31484fcbe0571e9c]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[dc0e626abd4c9e52]::result::Result<alloc[cb0f54882c31da79]::boxed::Box<dyn core[dc0e626abd4c9e52]::any::Any>, rustc_span[95ab60cea81a8973]::ErrorGuaranteed>>
  28:     0x7f61ec79808d - <rustc_interface[31484fcbe0571e9c]::queries::Queries>::ongoing_codegen
  29:     0x7f61ec7976a9 - <rustc_interface[31484fcbe0571e9c]::interface::Compiler>::enter::<rustc_driver_impl[9b9fd057b079c87d]::run_compiler::{closure#1}::{closure#2}, core[dc0e626abd4c9e52]::result::Result<core[dc0e626abd4c9e52]::option::Option<rustc_interface[31484fcbe0571e9c]::queries::Linker>, rustc_span[95ab60cea81a8973]::ErrorGuaranteed>>
  30:     0x7f61ec794e73 - std[9595413e0839bf8b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[31484fcbe0571e9c]::util::run_in_thread_pool_with_globals<rustc_interface[31484fcbe0571e9c]::interface::run_compiler<core[dc0e626abd4c9e52]::result::Result<(), rustc_span[95ab60cea81a8973]::ErrorGuaranteed>, rustc_driver_impl[9b9fd057b079c87d]::run_compiler::{closure#1}>::{closure#0}, core[dc0e626abd4c9e52]::result::Result<(), rustc_span[95ab60cea81a8973]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dc0e626abd4c9e52]::result::Result<(), rustc_span[95ab60cea81a8973]::ErrorGuaranteed>>
  31:     0x7f61ecdbc655 - <<std[9595413e0839bf8b]::thread::Builder>::spawn_unchecked_<rustc_interface[31484fcbe0571e9c]::util::run_in_thread_pool_with_globals<rustc_interface[31484fcbe0571e9c]::interface::run_compiler<core[dc0e626abd4c9e52]::result::Result<(), rustc_span[95ab60cea81a8973]::ErrorGuaranteed>, rustc_driver_impl[9b9fd057b079c87d]::run_compiler::{closure#1}>::{closure#0}, core[dc0e626abd4c9e52]::result::Result<(), rustc_span[95ab60cea81a8973]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dc0e626abd4c9e52]::result::Result<(), rustc_span[95ab60cea81a8973]::ErrorGuaranteed>>::{closure#1} as core[dc0e626abd4c9e52]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7f61ea376ff5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8594d8e8eb390362
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/alloc/src/boxed.rs:1985:9
  33:     0x7f61ea376ff5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc4f2baff9e44ab11
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/alloc/src/boxed.rs:1985:9
  34:     0x7f61ea376ff5 - std::sys::unix::thread::Thread::new::thread_start::hdf2074fec680ece7
                               at /rustc/cca7ee58110726983951a19d5fb7316d9243925d/library/std/src/sys/unix/thread.rs:108:17
  35:     0x7f61ea11bfd4 - start_thread
                               at ./nptl/pthread_create.c:442:8
  36:     0x7f61ea19c5bc - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  37:                0x0 - <unknown>

@tmiasko tmiasko 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. F-offset_of `#![feature(offset_of)]` labels May 28, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue May 30, 2023
…r=WaffleLapkin

offset_of: don't require type to be `Sized`

Fixes rust-lang#112051

~~The RFC [explicitly forbids](https://rust-lang.github.io/rfcs/3308-offset_of.html#limitations) non-`Sized` types, but it looks like only the fields being recursed into were checked. The sized check also seemed to have been completely missing for tuples~~
@bors bors closed this as completed in f589451 May 31, 2023
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. F-offset_of `#![feature(offset_of)]` 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