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: kcfi: unexpected parent of trait or impl item or item not found: ForeignMod #123640

Closed
matthiaskrgr opened this issue Apr 8, 2024 · 1 comment
Labels
A-sanitizers Area: Sanitizers for correctness and code quality. 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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

type Foo = fn();
extern "C" {
    fn meh(blah: Foo);
}

fn main() {
    meh as usize;
}

original:

type Foo = extern "C" fn(::std::ffi::CStr);
extern "C" {
    fn meh(blah: Foo);
}

fn main() {
    meh as usize;
}

Version information

rustc 1.79.0-nightly (537aab7a2 2024-04-08)
binary: rustc
commit-hash: 537aab7a2e7fe9cdf50b5ff18485e0793cd8db62
commit-date: 2024-04-08
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zsanitizer=kcfi -Cpanic=abort

Program output

warning: `extern` block uses type `fn()`, which is not FFI-safe
 --> /tmp/icemaker_global_tempdir.yf5SIeSDN0H6/rustc_testrunner_tmpdir_reporting.84KxMy4bVLRB/mvce.rs:3:18
  |
3 |     fn meh(blah: Foo);
  |                  ^^^ not FFI-safe
  |
  = help: consider using an `extern fn(...) -> ...` function pointer instead
  = note: this function pointer has Rust-specific calling convention
  = note: `#[warn(improper_ctypes)]` on by default

error: internal compiler error: compiler/rustc_ty_utils/src/assoc.rs:122:5: unexpected parent of trait or impl item or item not found: ForeignMod { abi: C { unwind: false }, items: [ForeignItemRef { id: ForeignItemId { owner_id: DefId(0:5 ~ mvce[b30d]::{extern#0}::meh) }, ident: meh#0, span: /tmp/icemaker_global_tempdir.yf5SIeSDN0H6/rustc_testrunner_tmpdir_reporting.84KxMy4bVLRB/mvce.rs:3:5: 3:23 (#0) }] }
 --> /tmp/icemaker_global_tempdir.yf5SIeSDN0H6/rustc_testrunner_tmpdir_reporting.84KxMy4bVLRB/mvce.rs:2:1
  |
2 | / extern "C" {
3 | |     fn meh(blah: Foo);
4 | | }
  | |_^

thread 'rustc' panicked at compiler/rustc_ty_utils/src/assoc.rs:122:5:
Box<dyn Any>
stack backtrace:
   0:     0x78e74a621885 - std::backtrace_rs::backtrace::libunwind::trace::h3c5d6be2ca224618
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x78e74a621885 - std::backtrace_rs::backtrace::trace_unsynchronized::h07f25bfbbc81f9b7
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x78e74a621885 - std::sys_common::backtrace::_print_fmt::hf0313e0fd41b1242
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x78e74a621885 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha80bcf755077e3a1
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x78e74a670b4b - core::fmt::rt::Argument::fmt::hea7d7a647aef4433
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/core/src/fmt/rt.rs:142:9
   5:     0x78e74a670b4b - core::fmt::write::h0eafe6836efd2236
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/core/src/fmt/mod.rs:1153:17
   6:     0x78e74a61647f - std::io::Write::write_fmt::hee25aa3e7912fe48
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/io/mod.rs:1843:15
   7:     0x78e74a62165e - std::sys_common::backtrace::_print::h0c8b5670573775f7
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x78e74a62165e - std::sys_common::backtrace::print::hb0c84899d27bc992
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x78e74a624159 - std::panicking::default_hook::{{closure}}::hdd10a62b37f83705
  10:     0x78e74a623e75 - std::panicking::default_hook::h491d7bd053f3c065
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/panicking.rs:291:9
  11:     0x78e746e5be5f - std[8cce646dcc9f51a2]::panicking::update_hook::<alloc[7e5e1bdade7884f3]::boxed::Box<rustc_driver_impl[b1693766bfe96bed]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x78e74a62485c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h673a5ec9e27814ea
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/alloc/src/boxed.rs:2032:9
  13:     0x78e74a62485c - std::panicking::rust_panic_with_hook::h2f18055510e9d6ac
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/panicking.rs:792:13
  14:     0x78e746e8bed4 - std[8cce646dcc9f51a2]::panicking::begin_panic::<rustc_errors[6ec141f8b50a2d31]::ExplicitBug>::{closure#0}
  15:     0x78e746e88c46 - std[8cce646dcc9f51a2]::sys_common::backtrace::__rust_end_short_backtrace::<std[8cce646dcc9f51a2]::panicking::begin_panic<rustc_errors[6ec141f8b50a2d31]::ExplicitBug>::{closure#0}, !>
  16:     0x78e746e88926 - std[8cce646dcc9f51a2]::panicking::begin_panic::<rustc_errors[6ec141f8b50a2d31]::ExplicitBug>
  17:     0x78e746e952d1 - <rustc_errors[6ec141f8b50a2d31]::diagnostic::BugAbort as rustc_errors[6ec141f8b50a2d31]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x78e7479e6e78 - <rustc_errors[6ec141f8b50a2d31]::DiagCtxt>::span_bug::<rustc_span[c8203a7ebedcd79e]::span_encoding::Span, alloc[7e5e1bdade7884f3]::string::String>
  19:     0x78e747a00f2d - rustc_middle[29872c107b60a246]::util::bug::opt_span_bug_fmt::<rustc_span[c8203a7ebedcd79e]::span_encoding::Span>::{closure#0}
  20:     0x78e747a00f5a - rustc_middle[29872c107b60a246]::ty::context::tls::with_opt::<rustc_middle[29872c107b60a246]::util::bug::opt_span_bug_fmt<rustc_span[c8203a7ebedcd79e]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x78e7479f4b3b - rustc_middle[29872c107b60a246]::ty::context::tls::with_context_opt::<rustc_middle[29872c107b60a246]::ty::context::tls::with_opt<rustc_middle[29872c107b60a246]::util::bug::opt_span_bug_fmt<rustc_span[c8203a7ebedcd79e]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x78e7479f3107 - rustc_middle[29872c107b60a246]::util::bug::span_bug_fmt::<rustc_span[c8203a7ebedcd79e]::span_encoding::Span>
  23:     0x78e7495ca880 - rustc_query_impl[51661ff1e116d73e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51661ff1e116d73e]::query_impl::associated_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[29872c107b60a246]::query::erase::Erased<[u8; 40usize]>>.cold
  24:     0x78e7484adc7a - rustc_query_system[2cf76174bd7e0814]::query::plumbing::try_execute_query::<rustc_query_impl[51661ff1e116d73e]::DynamicConfig<rustc_query_system[2cf76174bd7e0814]::query::caches::DefIdCache<rustc_middle[29872c107b60a246]::query::erase::Erased<[u8; 40usize]>>, false, false, false>, rustc_query_impl[51661ff1e116d73e]::plumbing::QueryCtxt, false>
  25:     0x78e7484ad970 - rustc_query_impl[51661ff1e116d73e]::query_impl::associated_item::get_query_non_incr::__rust_end_short_backtrace
  26:     0x78e748c1cccc - rustc_middle[29872c107b60a246]::query::plumbing::query_get_at::<rustc_query_system[2cf76174bd7e0814]::query::caches::DefIdCache<rustc_middle[29872c107b60a246]::query::erase::Erased<[u8; 40usize]>>>
  27:     0x78e74989f520 - <rustc_middle[29872c107b60a246]::ty::instance::Instance>::resolve_for_fn_ptr.cold
  28:     0x78e748c1696b - rustc_monomorphize[a54e4eb903c076d9]::collector::visit_fn_use
  29:     0x78e7459db067 - rustc_monomorphize[a54e4eb903c076d9]::collector::collect_items_rec::{closure#0}
  30:     0x78e7490415e6 - rustc_monomorphize[a54e4eb903c076d9]::collector::collect_items_rec
  31:     0x78e74903c0ac - rustc_monomorphize[a54e4eb903c076d9]::partitioning::collect_and_partition_mono_items
  32:     0x78e74903b6a8 - rustc_query_impl[51661ff1e116d73e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51661ff1e116d73e]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[29872c107b60a246]::query::erase::Erased<[u8; 24usize]>>
  33:     0x78e74903b68d - <rustc_query_impl[51661ff1e116d73e]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[7ebb3dbf9c5383ca]::ops::function::FnOnce<(rustc_middle[29872c107b60a246]::ty::context::TyCtxt, ())>>::call_once
  34:     0x78e749038214 - rustc_query_system[2cf76174bd7e0814]::query::plumbing::try_execute_query::<rustc_query_impl[51661ff1e116d73e]::DynamicConfig<rustc_query_system[2cf76174bd7e0814]::query::caches::SingleCache<rustc_middle[29872c107b60a246]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[51661ff1e116d73e]::plumbing::QueryCtxt, false>
  35:     0x78e749037f0b - rustc_query_impl[51661ff1e116d73e]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  36:     0x78e7491a4aaa - rustc_codegen_ssa[1df6559decbf1b9a]::base::codegen_crate::<rustc_codegen_llvm[daf017fde14aa476]::LlvmCodegenBackend>
  37:     0x78e7490ad502 - <rustc_codegen_llvm[daf017fde14aa476]::LlvmCodegenBackend as rustc_codegen_ssa[1df6559decbf1b9a]::traits::backend::CodegenBackend>::codegen_crate
  38:     0x78e7490ace85 - rustc_interface[e7aac3eeb74c4c0c]::passes::start_codegen
  39:     0x78e7490ac4ee - <rustc_interface[e7aac3eeb74c4c0c]::queries::Queries>::codegen_and_build_linker
  40:     0x78e748eeecd3 - rustc_interface[e7aac3eeb74c4c0c]::interface::run_compiler::<core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>, rustc_driver_impl[b1693766bfe96bed]::run_compiler::{closure#0}>::{closure#0}
  41:     0x78e748fcc01d - std[8cce646dcc9f51a2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[e7aac3eeb74c4c0c]::util::run_in_thread_with_globals<rustc_interface[e7aac3eeb74c4c0c]::util::run_in_thread_pool_with_globals<rustc_interface[e7aac3eeb74c4c0c]::interface::run_compiler<core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>, rustc_driver_impl[b1693766bfe96bed]::run_compiler::{closure#0}>::{closure#0}, core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>>::{closure#0}, core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>>
  42:     0x78e748fcbe2a - <<std[8cce646dcc9f51a2]::thread::Builder>::spawn_unchecked_<rustc_interface[e7aac3eeb74c4c0c]::util::run_in_thread_with_globals<rustc_interface[e7aac3eeb74c4c0c]::util::run_in_thread_pool_with_globals<rustc_interface[e7aac3eeb74c4c0c]::interface::run_compiler<core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>, rustc_driver_impl[b1693766bfe96bed]::run_compiler::{closure#0}>::{closure#0}, core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>>::{closure#0}, core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7ebb3dbf9c5383ca]::result::Result<(), rustc_span[c8203a7ebedcd79e]::ErrorGuaranteed>>::{closure#1} as core[7ebb3dbf9c5383ca]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x78e74a62e28b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hea2f762c1fe3db14
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/alloc/src/boxed.rs:2018:9
  44:     0x78e74a62e28b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h79ea2eedb7e4df53
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/alloc/src/boxed.rs:2018:9
  45:     0x78e74a62e28b - std::sys::pal::unix::thread::Thread::new::thread_start::h83279d19c2446390
                               at /rustc/537aab7a2e7fe9cdf50b5ff18485e0793cd8db62/library/std/src/sys/pal/unix/thread.rs:108:17
  46:     0x78e74a3cc55a - <unknown>
  47:     0x78e74a449a3c - <unknown>
  48:                0x0 - <unknown>

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.79.0-nightly (537aab7a2 2024-04-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z sanitizer=kcfi -C panic=abort -Z dump-mir-dir=dir

query stack during panic:
#0 [associated_item] computing associated item data for `meh`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to 1 previous error; 1 warning emitted


@matthiaskrgr matthiaskrgr 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. labels Apr 8, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 8, 2024
@compiler-errors
Copy link
Member

maybe fixed by #123635

@matthiaskrgr matthiaskrgr added the A-sanitizers Area: Sanitizers for correctness and code quality. label Apr 8, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sanitizers Area: Sanitizers for correctness and code quality. 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.
Projects
None yet
Development

No branches or pull requests

4 participants