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 pin is unavailable for diagnostic in no_core/no_std #116459

Closed
matthiaskrgr opened this issue Oct 5, 2023 · 2 comments
Closed

ICE when pin is unavailable for diagnostic in no_core/no_std #116459

matthiaskrgr opened this issue Oct 5, 2023 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

matthiaskrgr commented Oct 5, 2023

Code

related clippy ticket rust-lang/rust-clippy#11614
code from rustc_gcc

reduced with clippy suggestion applied with causes the rustc ice 😄

#![no_std]
#![no_core]
#[lang = "sized"]

pub(crate) unsafe auto trait Freeze {}

#[start]
fn main() -> isize {
    unsafe {
        libc::printf(().cast::<i8>(), c); // boom
    }
    0
}

original:

// Compiler:
//
// Run-time:
//   status: 0
//   stdout: 10
//     10
//     42

#![feature(auto_traits, lang_items, no_core, start, intrinsics)]

#![no_std]
#![no_core]

#[lang = "copy"]
pub unsafe trait Copy {}

unsafe impl Copy for bool {}
unsafe impl Copy for u8 {}
unsafe impl Copy for u16 {}
unsafe impl Copy for u32 {}
unsafe impl Copy for u64 {}
unsafe impl Copy for usize {}
unsafe impl Copy for i8 {}
unsafe impl Copy for i16 {}
unsafe impl Copy for i32 {}
unsafe impl Copy for isize {}
unsafe impl Copy for f32 {}
unsafe impl Copy for char {}

mod libc {
    #[link(name = "c")]
    extern "C" {
        pub fn printf(format: *const i8, ...) -> i32;
    }
}

/*
 * Core
 */

// Because we don't have core yet.
#[lang = "sized"]
pub trait Sized {}

#[lang = "receiver"]
trait Receiver {
}

#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}

/*
 * Code
 */

fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
    (
        a as u8, a, a as u32, a as usize, a as i8, a as i16, a as i32, a as isize, b as u8,
        b as u32,
    )
}

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
    let (_a, _b, c, d, _e, _f, _g, _h, _i, j) = int_cast(10, 42);
    unsafe {
        libc::printf((b"%d\n\0" as *const u8).cast::<i8>(), c);
        libc::printf(b"%ld\n\0" as *const u8 as *const i8, d);
        libc::printf(b"%ld\n\0" as *const u8 as *const i8, j);
    }
    0
}

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (cdca82c2c 2023-10-05)
binary: rustc
commit-hash: cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2
commit-date: 2023-10-05
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.2

Error output

<output>
Backtrace

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/method/suggest.rs:2544:57:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f6e3bb6385c - std::backtrace_rs::backtrace::libunwind::trace::h28a456392cd66d32
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f6e3bb6385c - std::backtrace_rs::backtrace::trace_unsynchronized::h5c84da83c00e15fa
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f6e3bb6385c - std::sys_common::backtrace::_print_fmt::hd30bc3b95bf09668
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f6e3bb6385c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2e74b6802afdb640
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f6e3bbca210 - core::fmt::rt::Argument::fmt::h7e35831c38d16bc1
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/fmt/rt.rs:142:9
   5:     0x7f6e3bbca210 - core::fmt::write::h0f918a578c0be12d
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/fmt/mod.rs:1116:17
   6:     0x7f6e3bb5688f - std::io::Write::write_fmt::h9ee98c4e35089d59
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/io/mod.rs:1763:15
   7:     0x7f6e3bb63644 - std::sys_common::backtrace::_print::h3ed4b78d937ec356
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f6e3bb63644 - std::sys_common::backtrace::print::h3e675480cae5f56e
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f6e3bb66457 - std::panicking::default_hook::{{closure}}::h22a92b4c71d18a7d
  10:     0x7f6e3bb6619a - std::panicking::default_hook::he8bab92e629ae59d
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:292:9
  11:     0x7f6e3e844c75 - std[d67efca46d603186]::panicking::update_hook::<alloc[f3bb8eaa3dde22e3]::boxed::Box<rustc_driver_impl[d618f54c2be2346e]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f6e3bb66bf8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3c886f63fe2b7816
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/alloc/src/boxed.rs:2021:9
  13:     0x7f6e3bb66bf8 - std::panicking::rust_panic_with_hook::h6be1a3e0bc63054b
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:735:13
  14:     0x7f6e3bb66906 - std::panicking::begin_panic_handler::{{closure}}::h5bd1e55345bdf2f4
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:601:13
  15:     0x7f6e3bb63d76 - std::sys_common::backtrace::__rust_end_short_backtrace::h22bd371f50ea61e7
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f6e3bb66682 - rust_begin_unwind
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/panicking.rs:597:5
  17:     0x7f6e3bbc6835 - core::panicking::panic_fmt::h75917a9680bc22eb
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/panicking.rs:72:14
  18:     0x7f6e3bbc68d3 - core::panicking::panic::h15b4be75acc6651d
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/core/src/panicking.rs:127:5
  19:     0x7f6e3ea131ad - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::suggest_traits_to_import
  20:     0x7f6e3e9fc783 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::report_no_match_method_error
  21:     0x7f6e3ea24533 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::report_method_error
  22:     0x7f6e3cfe15c9 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7f6e3e9bdc67 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::confirm_builtin_call
  24:     0x7f6e3cfc4259 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_call
  25:     0x7f6e3cfd801a - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7f6e3d05e312 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_block_with_expected
  27:     0x7f6e3cfd88da - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7f6e3d05e442 - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_block_with_expected
  29:     0x7f6e3cfd88da - <rustc_hir_typeck[a88ea1edd08f559a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:     0x7f6e3cc2f1f1 - rustc_hir_typeck[a88ea1edd08f559a]::check::check_fn
  31:     0x7f6e3cb79bc3 - rustc_hir_typeck[a88ea1edd08f559a]::typeck
  32:     0x7f6e3cd91e67 - rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7f6e3cd8bce2 - rustc_query_system[d3997528800dbdc6]::query::plumbing::try_execute_query::<rustc_query_impl[cd9bb7d0d059f9d0]::DynamicConfig<rustc_query_system[d3997528800dbdc6]::query::caches::VecCache<rustc_span[c5d4613e49b6ba27]::def_id::LocalDefId, rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::QueryCtxt, false>
  34:     0x7f6e3cd8d204 - rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7f6e3dd830fe - rustc_hir_analysis[eefb1cd51e18fbfa]::check_crate
  36:     0x7f6e3dd7866a - rustc_interface[9b2c388f81952165]::passes::analysis
  37:     0x7f6e3dfe00e7 - rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 1usize]>>
  38:     0x7f6e3dfdfcd6 - rustc_query_system[d3997528800dbdc6]::query::plumbing::try_execute_query::<rustc_query_impl[cd9bb7d0d059f9d0]::DynamicConfig<rustc_query_system[d3997528800dbdc6]::query::caches::SingleCache<rustc_middle[e5ef13c380fb2ac2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cd9bb7d0d059f9d0]::plumbing::QueryCtxt, false>
  39:     0x7f6e3dfdfa8d - rustc_query_impl[cd9bb7d0d059f9d0]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7f6e3def928d - std[d67efca46d603186]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[9b2c388f81952165]::util::run_in_thread_with_globals<rustc_interface[9b2c388f81952165]::interface::run_compiler<core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>, rustc_driver_impl[d618f54c2be2346e]::run_compiler::{closure#1}>::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>
  41:     0x7f6e3def8543 - <<std[d67efca46d603186]::thread::Builder>::spawn_unchecked_<rustc_interface[9b2c388f81952165]::util::run_in_thread_with_globals<rustc_interface[9b2c388f81952165]::interface::run_compiler<core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>, rustc_driver_impl[d618f54c2be2346e]::run_compiler::{closure#1}>::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65b0b3042b233d3]::result::Result<(), rustc_span[c5d4613e49b6ba27]::ErrorGuaranteed>>::{closure#1} as core[65b0b3042b233d3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7f6e3bb71b75 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h653bfcdacde55689
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/alloc/src/boxed.rs:2007:9
  43:     0x7f6e3bb71b75 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h546bbc1c1b1ae2df
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/alloc/src/boxed.rs:2007:9
  44:     0x7f6e3bb71b75 - std::sys::unix::thread::Thread::new::thread_start::ha44b87148468c512
                               at /rustc/cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2/library/std/src/sys/unix/thread.rs:108:17
  45:     0x7f6e3b9149eb - <unknown>
  46:     0x7f6e3b9987cc - <unknown>
  47:                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/rustc-ice-2023-10-05T20:50:16.655440773Z-189858.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0308, E0425, E0433, E0658.
For more information about an error, try `rustc --explain E0308`.

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints 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 Oct 5, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 5, 2023
@matthiaskrgr
Copy link
Member Author

@matthiaskrgr matthiaskrgr removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 5, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Oct 5, 2023

Please don't open issues for no_core. There's nothing to fix, as doing anything wrong there is like using an intrinsic wrong. Everything is tightly coupled with the compiler impl and fixes boil down to duplicating the things written in Rust code with complex equivalents in compiler code

@oli-obk oli-obk closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

3 participants