Skip to content

str as extern "C" arg causes compiler panic #80125

Closed
@IoTPanic

Description

@IoTPanic

Code

I am still getting used to Rust, and making plenty of mistakes, and I did the silly move of putting a str type as an argument for an external function. I understand this isn't correct rust and rewriting for correctness fixes the compiler panic.

// Silly me made this external callback signature, this is incorrect and how not
// to make a callback signature. Removing the str type fixes the issue.
type ExternCallback = extern "C" fn(*const u8, u32, str);

// Above type is used in a struct-
pub struct Client<'a> {
    // ...
    conn_tx_bind: ExternCallback,
    // ...
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

Error output

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.49.0-nightly (ffa2e7ae8 2020-10-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type staticlib --crate-type cdylib --crate-type lib

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

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_target/src/abi/call/x86_64.rs:158:47
stack backtrace:
   0:     0x7ff122cfea20 - std::backtrace_rs::backtrace::libunwind::trace::h303a626d53553a64
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:100:5
   1:     0x7ff122cfea20 - std::backtrace_rs::backtrace::trace_unsynchronized::h6abb882733c3f18c
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff122cfea20 - std::sys_common::backtrace::_print_fmt::h57829321f1d9217a
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7ff122cfea20 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h400b66a054640aac
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7ff122d6de9c - core::fmt::write::h1857a60b204f1b6a
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/fmt/mod.rs:1076:17
   5:     0x7ff122cf0642 - std::io::Write::write_fmt::h6453b28c8b27c6ea
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/io/mod.rs:1516:15
   6:     0x7ff122d039d5 - std::sys_common::backtrace::_print::h15cc4b3923cc9bc0
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7ff122d039d5 - std::sys_common::backtrace::print::h953c7be178c0674d
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7ff122d039d5 - std::panicking::default_hook::{{closure}}::h635d667f571198f0
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:208:50
   9:     0x7ff122d03678 - std::panicking::default_hook::h3bc2efb48060abaa
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:227:9
  10:     0x7ff1235cc618 - rustc_driver::report_ice::hbf1325c7565687ba
  11:     0x7ff122d04216 - std::panicking::rust_panic_with_hook::h887eb0c89f46b8b2
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:581:17
  12:     0x7ff122d03d99 - std::panicking::begin_panic_handler::{{closure}}::hf0d3f46d37dd3bc1
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:484:9
  13:     0x7ff122cfeebc - std::sys_common::backtrace::__rust_end_short_backtrace::h4bce8b52717576e3
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7ff122d03d59 - rust_begin_unwind
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:483:5
  15:     0x7ff122d6a1c1 - core::panicking::panic_fmt::hb15d6f55e8472f62
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/panicking.rs:85:14
  16:     0x7ff122d6a10d - core::panicking::panic::h5d1c61fed2502a5f
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/panicking.rs:50:5
  17:     0x7ff12665eaf2 - rustc_target::abi::call::x86_64::cast_target::h8f310b8a881734f3
  18:     0x7ff1239260ff - rustc_target::abi::call::x86_64::compute_abi_info::{{closure}}::hc9f3a1278d83e5c4
  19:     0x7ff1239f7448 - <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_middle::ty::layout::FnAbiExt<C>>::adjust_for_abi::h60db6c4404fb6b68
  20:     0x7ff1239f8870 - <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_middle::ty::layout::FnAbiExt<C>>::of_fn_ptr::hde6ff39c43d480d4
  21:     0x7ff1239c23d4 - <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type::h4992f20070fda05e
  22:     0x7ff1239c10ed - rustc_codegen_llvm::type_of::struct_llfields::h61b2b2bab04bcb79
  23:     0x7ff1239c1cc9 - <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type::h4992f20070fda05e
  24:     0x7ff123a15e8f - <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_codegen_llvm::abi::FnAbiLlvmExt>::llvm_type::h2eba71bc4a6fef8d
  25:     0x7ff12394280e - rustc_codegen_llvm::mono_item::<impl rustc_codegen_ssa::traits::declare::PreDefineMethods for rustc_codegen_llvm::context::CodegenCx>::predefine_fn::ha43f5adbb9cfa37b
  26:     0x7ff1238b8efc - rustc_codegen_llvm::base::compile_codegen_unit::module_codegen::h4c8c9c4c2a43bc33
  27:     0x7ff12391ec69 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::h858e942ea11c2f75
  28:     0x7ff12395878b - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task::h84330fcec5992c22
  29:     0x7ff1238b8b04 - rustc_codegen_llvm::base::compile_codegen_unit::h6e0644e09523002f
  30:     0x7ff1239fc354 - rustc_codegen_ssa::base::codegen_crate::h940381ed200dc2d9
  31:     0x7ff123a4dcd5 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::h3b5822f1feaab3d9
  32:     0x7ff123810855 - rustc_interface::passes::QueryContext::enter::h066717d47aa6a888
  33:     0x7ff12383d7a3 - rustc_interface::queries::Queries::ongoing_codegen::hb9f9c60cdf1bfb85
  34:     0x7ff1235e74ea - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h6eb07f11eba80bd6
  35:     0x7ff1235ae2a2 - rustc_span::with_source_map::h3820d41b3a036910
  36:     0x7ff1235e89c2 - rustc_interface::interface::create_compiler_and_run::h08ad396f4e7721e0
  37:     0x7ff1235d0d5a - scoped_tls::ScopedKey<T>::set::hd425a36fbe06985e
  38:     0x7ff1235ed9b5 - std::sys_common::backtrace::__rust_begin_short_backtrace::h23925571219dbc63
  39:     0x7ff12356b3ce - core::ops::function::FnOnce::call_once{{vtable.shim}}::h43b61b9af30b3669
  40:     0x7ff122d1321a - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h88864ee659ddb161
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/alloc/src/boxed.rs:1042:9
  41:     0x7ff122d1321a - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h9f03cbdc7ab33431
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/alloc/src/boxed.rs:1042:9
  42:     0x7ff122d1321a - std::sys::unix::thread::Thread::new::thread_start::h5979dd5560a11418
                               at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys/unix/thread.rs:89:17
  43:     0x7ff122c0b3e9 - start_thread
  44:     0x7ff122b28293 - __GI___clone
  45:                0x0 - <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions