Skip to content

internal compiler error: unexpected panic: thread 'rustc' panicked at 'called Option::unwrap() on a None value', compiler/rustc_target/src/abi/call/x86_64.rs:158:47 #94223

Closed
@horazont

Description

@horazont

Code

use std::os::raw::*;
use std::ffi::CStr;

pub trait Driver {
	fn resolution(&self) -> u32;
}

#[repr(C)]
pub struct CDriver {
	open: unsafe extern "C" fn(path: CStr, rd_obj: *mut c_void, wr_obj: *mut c_void) -> c_int,
	get_meta: unsafe extern "C" fn(name: *mut *const c_char, version: *mut *const c_char),
	get_resolution: unsafe extern "C" fn() -> u32,
}

#[repr(transparent)]
struct CDriverWrap {
	inner: CDriver,
}

impl Driver for CDriverWrap {
	fn resolution(&self) -> u32 {
		todo!();
	}
}

Notes:

  • Removing inner: CDriver removes the ICE
  • Removing any of the other fields from CDriver removes the ICE
  • Removing the trait + impl removes the ICE

Meta

NB: reproduces with beta + nightly via play.rust-lang.org

rustc --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_target/src/abi/call/x86_64.rs:158:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Full output + Backtrace

warning: field is never read: `inner`
  --> main.rs:17:2
   |
17 |     inner: CDriver,
   |     ^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

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: rust_begin_unwind
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
   2: core::panicking::panic
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:50:5
   3: rustc_target::abi::call::x86_64::cast_target
   4: rustc_target::abi::call::x86_64::compute_abi_info::{{closure}}
   5: rustc_target::abi::call::x86_64::compute_abi_info
   6: rustc_target::abi::call::FnAbi<Ty>::adjust_for_foreign_abi
   7: rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>::fn_abi_new_uncached
   8: rustc_middle::ty::layout::fn_abi_of_fn_ptr
   9: rustc_query_system::query::plumbing::get_query
  10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::fn_abi_of_fn_ptr
  11: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type
  12: rustc_codegen_llvm::type_of::struct_llfields
  13: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type
  14: rustc_codegen_llvm::type_of::struct_llfields
  15: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type
  16: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type
  17: <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_codegen_llvm::abi::FnAbiLlvmExt>::llvm_type
  18: rustc_codegen_llvm::mono_item::<impl rustc_codegen_ssa::traits::declare::PreDefineMethods for rustc_codegen_llvm::context::CodegenCx>::predefine_fn
  19: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  21: rustc_codegen_llvm::base::compile_codegen_unit
  22: rustc_codegen_ssa::base::codegen_crate
  23: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  24: rustc_interface::queries::Queries::ongoing_codegen
  25: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  26: rustc_span::with_source_map
  27: 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

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.57.0 (f1edd0429 2021-11-29) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

query stack during panic:
#0 [fn_abi_of_fn_ptr] computing call ABI of `unsafe extern "C" fn(std::ffi::c_str::CStr, *mut core::ffi::c_void, *mut core::ffi::c_void) -> i32` function pointers
end of query stack
warning: 1 warning emitted

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ABIArea: Concerning the application binary interface (ABI)A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions