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 with unsizing an extern type #79409

Open
DutchGhost opened this issue Nov 25, 2020 · 3 comments
Open

ICE with unsizing an extern type #79409

DutchGhost opened this issue Nov 25, 2020 · 3 comments
Labels
C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` F-unsized_locals `#![feature(unsized_locals)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

Code

#![feature(extern_types)]
#![feature(unsized_locals)]

extern { 
    type Device;
}

unsafe fn make_device() -> Box<Device> {
    Box::from_raw(0 as *mut _)
}

fn main() {
    let d: Device = unsafe { *make_device() };
}

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (1c389ffef 2020-11-24)

Error output

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `false`,
 right: `true`', compiler/rustc_codegen_llvm/src/builder.rs:445:9
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/panicking.rs:92:14
   2: <rustc_codegen_llvm::builder::Builder as rustc_codegen_ssa::traits::builder::BuilderMethods>::load_operand
   3: rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_consume
   4: rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_operand
   5: rustc_codegen_ssa::mir::block::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_block
   6: rustc_codegen_ssa::mir::codegen_mir
   7: rustc_codegen_ssa::base::codegen_instance
   8: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
   9: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  11: rustc_codegen_llvm::base::compile_codegen_unit
  12: rustc_codegen_ssa::base::codegen_crate
  13: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  14: rustc_interface::queries::Queries::ongoing_codegen
  15: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  16: rustc_span::with_source_map
  17: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

@DutchGhost DutchGhost 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 Nov 25, 2020
@jonas-schievink jonas-schievink added F-extern_types `#![feature(extern_types)]` F-unsized_locals `#![feature(unsized_locals)]` requires-nightly This issue requires a nightly compiler in some way. labels Nov 25, 2020
@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Nov 25, 2020

It seems clear to me that this shouldn't compile: there's no way to determine, even at run time, how many bytes of storage d needs (short of looking at the external code to see the size of Device, or calling some function in the compiled extern code to ask what the size of Device is, neither of which can be done in general). So we just can't support an unsized local of an extern type.

But this presents a pretty big problem: unsized locals of ?Sized generic parameter types. This program can't be correct (and indeed it ICEs the same way as the original code), but which part of it is in error?

#![feature(extern_types)]
#![feature(unsized_locals)]

extern {
    type Foo;
}

fn mk_foo() -> Box<Foo> {
    unimplemented!()
}

fn unsized_local_generic_parameter<T: ?Sized>(x: Box<T>) {
    // `unsized_locals` allows you to create locals of generic `?Sized`
    // parameter types
    let _x = *x;
}

fn main() {
    // But `extern_types` allows you to create pointers to extern types, and
    // pass them to functions expecting a pointer to a `?Sized` parameter type
    unsized_local_generic_parameter(mk_foo());
}

It seems to me that these features can't coexist as they are currently - extern_types breaks unsized_locals's fundamental assumption that at runtime we can determine the size of any type, even ?Sized ones.

I think this needs discussion from the lang team.

@Enselic
Copy link
Member

Enselic commented Aug 29, 2023

Triage: Still reproduces in Playground on current nightly, now at compiler/rustc_codegen_llvm/src/builder.rs:491:9.

@matthiaskrgr
Copy link
Member

thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/builder.rs:493:17:
unsized locals must not be `extern` types
stack backtrace:
   0:     0x7f5a38b8c7e6 - std::backtrace_rs::backtrace::libunwind::trace::h92488e4bb2264071
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f5a38b8c7e6 - std::backtrace_rs::backtrace::trace_unsynchronized::h97e02be157039c96
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5a38b8c7e6 - std::sys_common::backtrace::_print_fmt::h89a2b01cb3c33339
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f5a38b8c7e6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha79772b33774e7af
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f5a38bdeed0 - core::fmt::rt::Argument::fmt::h6d2228239beb9437
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/core/src/fmt/rt.rs:142:9
   5:     0x7f5a38bdeed0 - core::fmt::write::h9bcb8c2e898ce4b2
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f5a38b801df - std::io::Write::write_fmt::he7ba80727a5f8d75
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/io/mod.rs:1810:15
   7:     0x7f5a38b8c5c4 - std::sys_common::backtrace::_print::h9bd2ce6833902b42
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f5a38b8c5c4 - std::sys_common::backtrace::print::h09be6e715f2e0cc6
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f5a38b8f357 - std::panicking::default_hook::{{closure}}::h81ac1ebc9ea0357f
  10:     0x7f5a38b8f0b9 - std::panicking::default_hook::hfc7d2f2254fbbaf6
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:292:9
  11:     0x7f5a3b94e03c - std[e13db6861558cd66]::panicking::update_hook::<alloc[74e4b4cff019550b]::boxed::Box<rustc_driver_impl[f3f951fd75793e59]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f5a38b8faa6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h864b8f962a42f35c
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/alloc/src/boxed.rs:2030:9
  13:     0x7f5a38b8faa6 - std::panicking::rust_panic_with_hook::he5915ec9da668475
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:783:13
  14:     0x7f5a38b8f7b9 - std::panicking::begin_panic_handler::{{closure}}::h8912c4af58ae3d2d
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:649:13
  15:     0x7f5a38b8cce6 - std::sys_common::backtrace::__rust_end_short_backtrace::hfbc35781d5527627
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f5a38b8f550 - rust_begin_unwind
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:645:5
  17:     0x7f5a38bdb5d5 - core::panicking::panic_fmt::hc3a8fce14bfb5d21
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/core/src/panicking.rs:72:14
  18:     0x7f5a3ce77ab6 - <rustc_codegen_ssa[ab39db10c7744d49]::mir::FunctionCx<rustc_codegen_llvm[5233fca0b810d365]::builder::Builder>>::codegen_operand
  19:     0x7f5a3d48fb17 - <rustc_codegen_ssa[ab39db10c7744d49]::mir::FunctionCx<rustc_codegen_llvm[5233fca0b810d365]::builder::Builder>>::codegen_block
  20:     0x7f5a3d789783 - rustc_codegen_ssa[ab39db10c7744d49]::mir::codegen_mir::<rustc_codegen_llvm[5233fca0b810d365]::builder::Builder>
  21:     0x7f5a3d776f52 - rustc_codegen_llvm[5233fca0b810d365]::base::compile_codegen_unit::module_codegen
  22:     0x7f5a3db89cab - <rustc_codegen_llvm[5233fca0b810d365]::LlvmCodegenBackend as rustc_codegen_ssa[ab39db10c7744d49]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  23:     0x7f5a3dba85f9 - rustc_codegen_ssa[ab39db10c7744d49]::base::codegen_crate::<rustc_codegen_llvm[5233fca0b810d365]::LlvmCodegenBackend>
  24:     0x7f5a3dba7d35 - <rustc_codegen_llvm[5233fca0b810d365]::LlvmCodegenBackend as rustc_codegen_ssa[ab39db10c7744d49]::traits::backend::CodegenBackend>::codegen_crate
  25:     0x7f5a3dba60f0 - rustc_interface[1dfaeeba2be2315d]::passes::start_codegen
  26:     0x7f5a3dba5826 - <rustc_interface[1dfaeeba2be2315d]::queries::Queries>::codegen_and_build_linker
  27:     0x7f5a3d9169de - rustc_interface[1dfaeeba2be2315d]::interface::run_compiler::<core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>, rustc_driver_impl[f3f951fd75793e59]::run_compiler::{closure#0}>::{closure#0}
  28:     0x7f5a3dbd04c6 - std[e13db6861558cd66]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_with_globals<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_pool_with_globals<rustc_interface[1dfaeeba2be2315d]::interface::run_compiler<core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>, rustc_driver_impl[f3f951fd75793e59]::run_compiler::{closure#0}>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>
  29:     0x7f5a3dbd02f3 - <<std[e13db6861558cd66]::thread::Builder>::spawn_unchecked_<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_with_globals<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_pool_with_globals<rustc_interface[1dfaeeba2be2315d]::interface::run_compiler<core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>, rustc_driver_impl[f3f951fd75793e59]::run_compiler::{closure#0}>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#1} as core[6f83431ac1278f74]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7f5a38b999d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb53ed9031b4e247a
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/alloc/src/boxed.rs:2016:9
  31:     0x7f5a38b999d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfb9a49e9b795584d
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/alloc/src/boxed.rs:2016:9
  32:     0x7f5a38b999d5 - std::sys::unix::thread::Thread::new::thread_start::h4db5c6ec45610220
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys/unix/thread.rs:108:17
  33:     0x7f5a389859eb - <unknown>
  34:     0x7f5a38a097cc - <unknown>
  35:                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 attach the file at `/tmp/ices/rustc-ice-2024-01-09T22_37_00-1727225.txt` to your bug report

query stack during panic:
end of query stack
warning: 2 warnings emitted

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 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. F-extern_types `#![feature(extern_types)]` F-unsized_locals `#![feature(unsized_locals)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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