rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
93.24k stars 12.02k forks source link

ICE: `is not a body node:` #124319

Open matthiaskrgr opened 1 week ago

matthiaskrgr commented 1 week ago

Code

static mut FOO: Foo = Foo {
    field: &mut [42] as *mut [i32] as *mut i32,
};

struct Foo {
    field: *mut i32,
}

unsafe impl Sync for Foo {}

fn main() {
    assert_eq!(unsafe { *FOO.field = 69; *FOO.field }, 69);
}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (40dcd796d 2024-04-23)
binary: rustc
commit-hash: 40dcd796d094b911b8b7b55a0519fb8e3d21680f
commit-date: 2024-04-23
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Error output

`rustc -Zcodegen-backend=cranelift -Zpolymorphize=on file.rs

<output>
Backtrace

``` error: internal compiler error: /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/compiler/rustc_middle/src/hir/map/mod.rs:294:19: DefId(0:8 ~ static_raw_pointer_interning2_b279bb2261a8e9dcc54e36f9dd1cbb13405743be[669d]::FOO::{constant#0}) is not a body node: Static { mutability: Mut, nested: true } thread 'rustc' panicked at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/compiler/rustc_middle/src/hir/map/mod.rs:294:19: Box stack backtrace: 0: 0x7e3f08ecb935 - std::backtrace_rs::backtrace::libunwind::trace::h37b813bf04fe68da at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x7e3f08ecb935 - std::backtrace_rs::backtrace::trace_unsynchronized::hab24bc6e401550c9 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7e3f08ecb935 - std::sys_common::backtrace::_print_fmt::h0ed8afb1f8b1b186 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7e3f08ecb935 - ::fmt::hfa93c2668fd48884 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7e3f08f1aa6b - core::fmt::rt::Argument::fmt::h8f2440e6cfd8c172 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/core/src/fmt/rt.rs:165:63 5: 0x7e3f08f1aa6b - core::fmt::write::h519cf493456154e9 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/core/src/fmt/mod.rs:1157:21 6: 0x7e3f08ec053f - std::io::Write::write_fmt::hdcb94510ddf24313 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/io/mod.rs:1832:15 7: 0x7e3f08ecb70e - std::sys_common::backtrace::_print::h3db464b21f5c5cd6 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7e3f08ecb70e - std::sys_common::backtrace::print::h4f94a0796297aaac at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7e3f08ece079 - std::panicking::default_hook::{{closure}}::h73742c7c49d6bdc6 10: 0x7e3f08ecddbd - std::panicking::default_hook::h03259a6dd63e0537 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/panicking.rs:298:9 11: 0x7e3f0583caab - std[716fbccb88eab441]::panicking::update_hook::>::{closure#0} 12: 0x7e3f08ece776 - as core::ops::function::Fn>::call::h47f10f0c9cee1061 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/alloc/src/boxed.rs:2036:9 13: 0x7e3f08ece776 - std::panicking::rust_panic_with_hook::hdef93bb45d728673 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/panicking.rs:799:13 14: 0x7e3f0586cd84 - std[716fbccb88eab441]::panicking::begin_panic::::{closure#0} 15: 0x7e3f05869736 - std[716fbccb88eab441]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7e3f05864d36 - std[716fbccb88eab441]::panicking::begin_panic:: 17: 0x7e3f05876001 - ::emit_producing_guarantee 18: 0x7e3f05d1cf4c - rustc_middle[98123958515d0133]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x7e3f05d0478a - rustc_middle[98123958515d0133]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x7e3f05d0460b - rustc_middle[98123958515d0133]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7e3f03fe54e0 - rustc_middle[98123958515d0133]::util::bug::bug_fmt 22: 0x7e3f05ec7989 - ::body_const_context:: 23: 0x7e3f07403490 - rustc_query_impl[dc957dd79d9c76d8]::plumbing::__rust_begin_short_backtrace::> 24: 0x7e3f07402d19 - rustc_query_system[dc3c1c377815842a]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[dc957dd79d9c76d8]::plumbing::QueryCtxt, false> 25: 0x7e3f07402a28 - rustc_query_impl[dc957dd79d9c76d8]::query_impl::unused_generic_params::get_query_non_incr::__rust_end_short_backtrace 26: 0x7e3f05d0ff64 - rustc_middle[98123958515d0133]::ty::instance::polymorphize 27: 0x7e3f05d0fd3b - ::polymorphize 28: 0x7e3ef881f264 - rustc_codegen_cranelift[d6f88c39893ffeba]::constant::data_id_for_static 29: 0x7e3ef881d1ba - ::finalize 30: 0x7e3ef8828256 - rustc_codegen_cranelift[d6f88c39893ffeba]::driver::aot::module_codegen::{closure#0} 31: 0x7e3ef8826487 - rustc_codegen_cranelift[d6f88c39893ffeba]::driver::aot::module_codegen 32: 0x7e3ef8833789 - rustc_codegen_cranelift[d6f88c39893ffeba]::driver::aot::run_aot 33: 0x7e3ef8860f31 - ::codegen_crate 34: 0x7e3f07aa629d - rustc_interface[9c928a10bc10dd72]::passes::start_codegen 35: 0x7e3f07aa5918 - ::codegen_and_build_linker 36: 0x7e3f077f3236 - rustc_interface[9c928a10bc10dd72]::interface::run_compiler::, rustc_driver_impl[2cb9e512ff9c01af]::run_compiler::{closure#0}>::{closure#1} 37: 0x7e3f077dcd49 - std[716fbccb88eab441]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[2cb9e512ff9c01af]::run_compiler::{closure#0}>::{closure#1}, core[6d1459b4b1018518]::result::Result<(), rustc_span[a5597b78f846b7ef]::ErrorGuaranteed>>::{closure#0}, core[6d1459b4b1018518]::result::Result<(), rustc_span[a5597b78f846b7ef]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6d1459b4b1018518]::result::Result<(), rustc_span[a5597b78f846b7ef]::ErrorGuaranteed>> 38: 0x7e3f077dcafa - <::spawn_unchecked_, rustc_driver_impl[2cb9e512ff9c01af]::run_compiler::{closure#0}>::{closure#1}, core[6d1459b4b1018518]::result::Result<(), rustc_span[a5597b78f846b7ef]::ErrorGuaranteed>>::{closure#0}, core[6d1459b4b1018518]::result::Result<(), rustc_span[a5597b78f846b7ef]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6d1459b4b1018518]::result::Result<(), rustc_span[a5597b78f846b7ef]::ErrorGuaranteed>>::{closure#2} as core[6d1459b4b1018518]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 39: 0x7e3f08ed860b - as core::ops::function::FnOnce>::call_once::h2aa7472c794092b9 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/alloc/src/boxed.rs:2022:9 40: 0x7e3f08ed860b - as core::ops::function::FnOnce>::call_once::ha0ae72bf75088542 at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/alloc/src/boxed.rs:2022:9 41: 0x7e3f08ed860b - std::sys::pal::unix::thread::Thread::new::thread_start::ha07f7010bd7bf45c at /rustc/7f2fc33da6633f5a764ddc263c769b6b2873d167/library/std/src/sys/pal/unix/thread.rs:108:17 42: 0x7e3f026a955a - 43: 0x7e3f02726a3c - 44: 0x0 - 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 make sure that you have updated to the latest nightly note: please attach the file at `/tmp/im/rustc-ice-2024-04-24T04_15_14-3181386.txt` to your bug report note: compiler flags: -Z codegen-backend=cranelift -Z polymorphize=on query stack during panic: #0 [unused_generic_params] determining which generic parameters are unused by `FOO::{constant#0}` end of query stack ```

matthiaskrgr commented 1 week ago

Not sure what cranelift does different, havn't been able to trigger the ICE with llvm so far.

bjorn3 commented 1 week ago

Maybe I'm not supposed to call polymorphize on a static Instance?