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 compiling for x86_64-pc-windows-gnu when passing a ZST using the "sysv64" ABI #125850

Closed
beetrees opened this issue Jun 1, 2024 · 1 comment · Fixed by #125854
Closed
Labels
A-abi Area: Concerning the application binary interface (ABI). C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-windows-gnu Toolchain: GNU, Operating system: Windows O-x86_64 Target: x86-64 processors (like x86_64-*) S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@beetrees
Copy link
Contributor

beetrees commented Jun 1, 2024

Code

pub extern "sysv64" fn f(_: ()) {}

Compiled with rustc --target x86_64-pc-windows-gnu --crate-type lib code.rs.

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (ada5e2c7b 2024-05-31)
binary: rustc
commit-hash: ada5e2c7b5427a591e30baeeee2698a5eb6db0bd
commit-date: 2024-05-31
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

warning: `extern` fn uses type `()`, which is not FFI-safe
 --> a.rs:1:29
  |
1 | pub extern "sysv64" fn f(_: ()) {}
  |                             ^^ not FFI-safe
  |
  = help: consider using a struct instead
  = note: tuples have unspecified layout
  = note: `#[warn(improper_ctypes_definitions)]` on by default
Backtrace

thread 'rustc' panicked at compiler/rustc_target/src/abi/call/x86_64.rs:158:47:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f4c3d239df5 - std::backtrace_rs::backtrace::libunwind::trace::h0bda62405550d460
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f4c3d239df5 - std::backtrace_rs::backtrace::trace_unsynchronized::h92e1f091fb842a50
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f4c3d239df5 - std::backtrace::Backtrace::create::h5661919a927f881f
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/backtrace.rs:331:13
   3:     0x7f4c3d239d45 - std::backtrace::Backtrace::force_capture::h92377330a7e0012e
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/backtrace.rs:312:9
   4:     0x7f4c39934146 - std[a75323165fe08653]::panicking::update_hook::<alloc[2577b08d1a5511d8]::boxed::Box<rustc_driver_impl[9be41471faca984]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7f4c3d254c0b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3a2a9442c441a378
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2077:9
   6:     0x7f4c3d254c0b - std::panicking::rust_panic_with_hook::he3c87e486ff05d6b
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:799:13
   7:     0x7f4c3d25494b - std::panicking::begin_panic_handler::{{closure}}::h01ce2bfd91e16fe0
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:656:13
   8:     0x7f4c3d252189 - std::sys_common::backtrace::__rust_end_short_backtrace::ha36f641af1493052
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:171:18
   9:     0x7f4c3d2546b7 - rust_begin_unwind
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:652:5
  10:     0x7f4c3d29ec53 - core::panicking::panic_fmt::h8cbe41bd36f1ccd3
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:72:14
  11:     0x7f4c3d29ecfc - core::panicking::panic::he30e77852aaaf38d
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:146:5
  12:     0x7f4c3d29e999 - core::option::unwrap_failed::h63606462f53741c7
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/option.rs:1987:5
  13:     0x7f4c3a38af5f - rustc_target[f4bda3b6c505fe35]::abi::call::x86_64::cast_target
  14:     0x7f4c3c63d62d - rustc_target[f4bda3b6c505fe35]::abi::call::x86_64::compute_abi_info::<rustc_middle[353648fe55f979cd]::ty::Ty, rustc_middle[353648fe55f979cd]::ty::layout::LayoutCx<rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>>::{closure#0}.cold
  15:     0x7f4c3a578fd3 - rustc_target[f4bda3b6c505fe35]::abi::call::x86_64::compute_abi_info::<rustc_middle[353648fe55f979cd]::ty::Ty, rustc_middle[353648fe55f979cd]::ty::layout::LayoutCx<rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>>
  16:     0x7f4c3b4583b5 - rustc_ty_utils[9b1887357cf581ca]::abi::fn_abi_new_uncached
  17:     0x7f4c3b449934 - rustc_ty_utils[9b1887357cf581ca]::abi::fn_abi_of_instance
  18:     0x7f4c3b4481f3 - rustc_query_impl[9b16a2dee6878131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b16a2dee6878131]::query_impl::fn_abi_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 16usize]>>
  19:     0x7f4c3b44617b - rustc_query_system[965e295a0f1b428c]::query::plumbing::try_execute_query::<rustc_query_impl[9b16a2dee6878131]::DynamicConfig<rustc_query_system[965e295a0f1b428c]::query::caches::DefaultCache<rustc_middle[353648fe55f979cd]::ty::ParamEnvAnd<(rustc_middle[353648fe55f979cd]::ty::instance::Instance, &rustc_middle[353648fe55f979cd]::ty::list::RawList<(), rustc_middle[353648fe55f979cd]::ty::Ty>)>, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[9b16a2dee6878131]::plumbing::QueryCtxt, false>
  20:     0x7f4c3b445dc5 - rustc_query_impl[9b16a2dee6878131]::query_impl::fn_abi_of_instance::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7f4c3807ce27 - <rustc_codegen_llvm[ca3c5a28d69b7154]::context::CodegenCx as rustc_codegen_ssa[4a5dcf6ebd8d637e]::traits::declare::PreDefineMethods>::predefine_fn
  22:     0x7f4c3baf9667 - rustc_codegen_llvm[ca3c5a28d69b7154]::base::compile_codegen_unit::module_codegen
  23:     0x7f4c3baf597c - <rustc_codegen_llvm[ca3c5a28d69b7154]::LlvmCodegenBackend as rustc_codegen_ssa[4a5dcf6ebd8d637e]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  24:     0x7f4c3bd04801 - rustc_codegen_ssa[4a5dcf6ebd8d637e]::base::codegen_crate::<rustc_codegen_llvm[ca3c5a28d69b7154]::LlvmCodegenBackend>
  25:     0x7f4c3bcf7c4c - <rustc_codegen_llvm[ca3c5a28d69b7154]::LlvmCodegenBackend as rustc_codegen_ssa[4a5dcf6ebd8d637e]::traits::backend::CodegenBackend>::codegen_crate
  26:     0x7f4c3bcf75df - rustc_interface[cb0c5c0af19cf814]::passes::start_codegen
  27:     0x7f4c3bcf6c5a - <rustc_interface[cb0c5c0af19cf814]::queries::Queries>::codegen_and_build_linker
  28:     0x7f4c3ba7723c - rustc_interface[cb0c5c0af19cf814]::interface::run_compiler::<core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>, rustc_driver_impl[9be41471faca984]::run_compiler::{closure#0}>::{closure#1}
  29:     0x7f4c3ba410c9 - std[a75323165fe08653]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_with_globals<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_pool_with_globals<rustc_interface[cb0c5c0af19cf814]::interface::run_compiler<core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>, rustc_driver_impl[9be41471faca984]::run_compiler::{closure#0}>::{closure#1}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>
  30:     0x7f4c3ba40e80 - <<std[a75323165fe08653]::thread::Builder>::spawn_unchecked_<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_with_globals<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_pool_with_globals<rustc_interface[cb0c5c0af19cf814]::interface::run_compiler<core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>, rustc_driver_impl[9be41471faca984]::run_compiler::{closure#0}>::{closure#1}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#2} as core[bd782e33ccb6b408]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7f4c3d25ebfb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h149a8f3bd2b6d616
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9
  32:     0x7f4c3d25ebfb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc8ac52b5c9166594
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9
  33:     0x7f4c3d25ebfb - std::sys::pal::unix::thread::Thread::new::thread_start::h4464ec80ffa1747a
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys/pal/unix/thread.rs:108:17
  34:     0x7f4c3d0181b7 - start_thread
  35:     0x7f4c3d09a39c - __GI___clone3
  36:                0x0 - <unknown>


rustc version: 1.80.0-nightly (ada5e2c7b 2024-05-31)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [fn_abi_of_instance] computing call ABI of `f`
end of query stack

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

beetrees commented Jun 1, 2024

@rustbot label +A-abi +O-windows-gnu +O-x86_64

@rustbot rustbot added A-abi Area: Concerning the application binary interface (ABI). O-windows-gnu Toolchain: GNU, Operating system: Windows O-x86_64 Target: x86-64 processors (like x86_64-*) labels Jun 1, 2024
@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 18, 2024
Move ZST ABI handling to `rustc_target`

Currently, target specific handling of ZST function call ABI (specifically passing them indirectly instead of ignoring them) is handled in `rustc_ty_utils`, whereas all other target specific function call ABI handling is located in `rustc_target`. This PR moves the ZST handling to `rustc_target` so that all the target-specific function call ABI handling is in one place. In the process of doing so, this PR fixes rust-lang#125850 by ensuring that ZST arguments are always correctly ignored in the x86-64 `"sysv64"` ABI; any code which would be affected by this fix would have ICEd before this PR. Tests are also added using `#[rustc_abi(debug)]` to ensure this behaviour does not regress.

Fixes rust-lang#125850
@bors bors closed this as completed in d0293c6 Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-abi Area: Concerning the application binary interface (ABI). C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-windows-gnu Toolchain: GNU, Operating system: Windows O-x86_64 Target: x86-64 processors (like x86_64-*) S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

3 participants