Skip to content

ICE: pretty: Unexpected def kind GlobalAsm #138260

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Zdump-mir=all use std::arch::{asm, global_asm}; global_asm!("mov x0, {}", const constfn(5) + constfn(5));

original:

//@ only-aarch64 //@ run-pass //@ needs-asm-support use std::arch::{asm, global_asm}; fn const_generic<const X: usize>() -> usize { unsafe { let a: usize; asm!("mov {}, {}", out(reg) a, const X); a } } const fn constfn(x: usize) -> usize { x } fn main() { unsafe { let a: usize; asm!("mov {}, {}", out(reg) a, const 5); assert_eq!(a, 5); let b: usize; asm!("mov {}, {}", out(reg) b, const constfn(5)); assert_eq!(b, 5); let c: usize; asm!("mov {}, {}", out(reg) c, const constfn(5) + constfn(5)); assert_eq!(c, 10); } let d = const_generic::<5>(); assert_eq!(d, 5); } global_asm!("mov x0, {}", const 5); global_asm!("mov x0, {}", const constfn(5)); global_asm!("mov x0, {}", const constfn(5) + constfn(5));

Version information

rustc 1.87.0-nightly (a96fa317d 2025-03-09) binary: rustc commit-hash: a96fa317d78c78a9de996afd317603c6970efc0d commit-date: 2025-03-09 host: x86_64-unknown-linux-gnu release: 1.87.0-nightly LLVM version: 20.1.0 

Possibly related line of code:

}
(DefKind::Static { safety: _, mutability: hir::Mutability::Mut, nested: false }, _) => {
write!(w, "static mut ")?
}
(_, _) if is_function => write!(w, "fn ")?,
(DefKind::AnonConst | DefKind::InlineConst, _) => {} // things like anon const, not an item
_ => bug!("Unexpected def kind {:?}", kind),
}
ty::print::with_forced_impl_filename_line! {
// see notes on #41697 elsewhere
write!(w, "{}", tcx.def_path_str(def_id))?
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zdump-mir=all

Program output

warning: unused import: `asm` --> /tmp/icemaker_global_tempdir.QU8cCxU1sTAN/rustc_testrunner_tmpdir_reporting.aSlZSaU8UpOL/mvce.rs:1:17 | 1 | use std::arch::{asm, global_asm}; | ^^^ | = note: `#[warn(unused_imports)]` on by default error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.QU8cCxU1sTAN/rustc_testrunner_tmpdir_reporting.aSlZSaU8UpOL/mvce.rs:3:58 | 3 | global_asm!("mov x0, {}", const constfn(5) + constfn(5)); | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.QU8cCxU1sTAN/rustc_testrunner_tmpdir_reporting.aSlZSaU8UpOL/mvce.rs` error[E0425]: cannot find function `constfn` in this scope --> /tmp/icemaker_global_tempdir.QU8cCxU1sTAN/rustc_testrunner_tmpdir_reporting.aSlZSaU8UpOL/mvce.rs:3:33 | 3 | global_asm!("mov x0, {}", const constfn(5) + constfn(5)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `constfn` in this scope --> /tmp/icemaker_global_tempdir.QU8cCxU1sTAN/rustc_testrunner_tmpdir_reporting.aSlZSaU8UpOL/mvce.rs:3:46 | 3 | global_asm!("mov x0, {}", const constfn(5) + constfn(5)); | ^^^^^^^ not found in this scope error: internal compiler error: compiler/rustc_middle/src/mir/pretty.rs:657:14: Unexpected def kind GlobalAsm thread 'rustc' panicked at compiler/rustc_middle/src/mir/pretty.rs:657:14: Box<dyn Any> stack backtrace: 0: 0x7df246fba414 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h52c7f0550840b8f9 1: 0x7df247805bee - core::fmt::write::hee3b35a23fdf4ab3 2: 0x7df248c21e91 - std::io::Write::write_fmt::hf49dbaa0e19fcf6b 3: 0x7df246fba272 - std::sys::backtrace::BacktraceLock::print::hc7c25359d1b81c79 4: 0x7df246fbcb98 - std::panicking::default_hook::{{closure}}::h384e40742b2d89cc 5: 0x7df246fbc6b7 - std::panicking::default_hook::hdad5dc41d6be2842 6: 0x7df24610c93f - std[af3b6eacc99eae20]::panicking::update_hook::<alloc[63c0b52934c5697b]::boxed::Box<rustc_driver_impl[c2cc76304700d71f]::install_ice_hook::{closure#1}>>::{closure#0} 7: 0x7df246fbd403 - std::panicking::rust_panic_with_hook::h45ecb165eb6636c0 8: 0x7df246149071 - std[af3b6eacc99eae20]::panicking::begin_panic::<rustc_errors[4dd87fb07da1f12a]::ExplicitBug>::{closure#0} 9: 0x7df24613d596 - std[af3b6eacc99eae20]::sys::backtrace::__rust_end_short_backtrace::<std[af3b6eacc99eae20]::panicking::begin_panic<rustc_errors[4dd87fb07da1f12a]::ExplicitBug>::{closure#0}, !> 10: 0x7df24613a12b - std[af3b6eacc99eae20]::panicking::begin_panic::<rustc_errors[4dd87fb07da1f12a]::ExplicitBug> 11: 0x7df246152bd1 - <rustc_errors[4dd87fb07da1f12a]::diagnostic::BugAbort as rustc_errors[4dd87fb07da1f12a]::diagnostic::EmissionGuarantee>::emit_producing_guarantee 12: 0x7df2467298da - rustc_middle[7aa79b75868ccd38]::util::bug::opt_span_bug_fmt::<rustc_span[6f95e09a31d512b0]::span_encoding::Span>::{closure#0} 13: 0x7df24671143a - rustc_middle[7aa79b75868ccd38]::ty::context::tls::with_opt::<rustc_middle[7aa79b75868ccd38]::util::bug::opt_span_bug_fmt<rustc_span[6f95e09a31d512b0]::span_encoding::Span>::{closure#0}, !>::{closure#0} 14: 0x7df2467112ab - rustc_middle[7aa79b75868ccd38]::ty::context::tls::with_context_opt::<rustc_middle[7aa79b75868ccd38]::ty::context::tls::with_opt<rustc_middle[7aa79b75868ccd38]::util::bug::opt_span_bug_fmt<rustc_span[6f95e09a31d512b0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !> 15: 0x7df2449d86b0 - rustc_middle[7aa79b75868ccd38]::util::bug::bug_fmt 16: 0x7df2466e6b55 - rustc_middle[7aa79b75868ccd38]::mir::pretty::write_mir_intro 17: 0x7df24682d0ec - rustc_middle[7aa79b75868ccd38]::mir::pretty::write_mir_fn::<rustc_mir_transform[8791defed41099cf]::pass_manager::dump_mir_for_pass::{closure#0}> 18: 0x7df24780b326 - rustc_mir_transform[8791defed41099cf]::mir_built 19: 0x7df247809c47 - rustc_query_impl[417e50fa6d8979be]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[417e50fa6d8979be]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 8usize]>> 20: 0x7df247b500cc - rustc_query_system[ed803ae4c980bdd6]::query::plumbing::try_execute_query::<rustc_query_impl[417e50fa6d8979be]::DynamicConfig<rustc_data_structures[2d87afbd7b950794]::vec_cache::VecCache<rustc_span[6f95e09a31d512b0]::def_id::LocalDefId, rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[ed803ae4c980bdd6]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[417e50fa6d8979be]::plumbing::QueryCtxt, false> 21: 0x7df247b4fc8b - rustc_query_impl[417e50fa6d8979be]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 22: 0x7df244e1b8bb - rustc_mir_transform[8791defed41099cf]::mir_promoted 23: 0x7df247d2fe92 - rustc_query_impl[417e50fa6d8979be]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[417e50fa6d8979be]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 16usize]>> 24: 0x7df247d3014e - rustc_query_system[ed803ae4c980bdd6]::query::plumbing::try_execute_query::<rustc_query_impl[417e50fa6d8979be]::DynamicConfig<rustc_data_structures[2d87afbd7b950794]::vec_cache::VecCache<rustc_span[6f95e09a31d512b0]::def_id::LocalDefId, rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 16usize]>, rustc_query_system[ed803ae4c980bdd6]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[417e50fa6d8979be]::plumbing::QueryCtxt, false> 25: 0x7df247d2fd8d - rustc_query_impl[417e50fa6d8979be]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace 26: 0x7df248a1032d - rustc_query_impl[417e50fa6d8979be]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[417e50fa6d8979be]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 8usize]>> 27: 0x7df247b500cc - rustc_query_system[ed803ae4c980bdd6]::query::plumbing::try_execute_query::<rustc_query_impl[417e50fa6d8979be]::DynamicConfig<rustc_data_structures[2d87afbd7b950794]::vec_cache::VecCache<rustc_span[6f95e09a31d512b0]::def_id::LocalDefId, rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[ed803ae4c980bdd6]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[417e50fa6d8979be]::plumbing::QueryCtxt, false> 28: 0x7df247b4fbcb - rustc_query_impl[417e50fa6d8979be]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace 29: 0x7df247c5e53a - rustc_interface[91d83e268fb48030]::passes::run_required_analyses 30: 0x7df2487872b8 - rustc_interface[91d83e268fb48030]::passes::analysis 31: 0x7df248787297 - rustc_query_impl[417e50fa6d8979be]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[417e50fa6d8979be]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 0usize]>> 32: 0x7df2488f8201 - rustc_query_system[ed803ae4c980bdd6]::query::plumbing::try_execute_query::<rustc_query_impl[417e50fa6d8979be]::DynamicConfig<rustc_query_system[ed803ae4c980bdd6]::query::caches::SingleCache<rustc_middle[7aa79b75868ccd38]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[417e50fa6d8979be]::plumbing::QueryCtxt, false> 33: 0x7df2488f7ef4 - rustc_query_impl[417e50fa6d8979be]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 34: 0x7df2489474fc - rustc_interface[91d83e268fb48030]::passes::create_and_enter_global_ctxt::<core[ed80027c49f06cd6]::option::Option<rustc_interface[91d83e268fb48030]::queries::Linker>, rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0} 35: 0x7df2489374ee - rustc_interface[91d83e268fb48030]::interface::run_compiler::<(), rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}>::{closure#1} 36: 0x7df248771248 - std[af3b6eacc99eae20]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[91d83e268fb48030]::util::run_in_thread_with_globals<rustc_interface[91d83e268fb48030]::util::run_in_thread_pool_with_globals<rustc_interface[91d83e268fb48030]::interface::run_compiler<(), rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()> 37: 0x7df248771b34 - <<std[af3b6eacc99eae20]::thread::Builder>::spawn_unchecked_<rustc_interface[91d83e268fb48030]::util::run_in_thread_with_globals<rustc_interface[91d83e268fb48030]::util::run_in_thread_pool_with_globals<rustc_interface[91d83e268fb48030]::interface::run_compiler<(), rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ed80027c49f06cd6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 38: 0x7df248772f2b - std::sys::pal::unix::thread::Thread::new::thread_start::h3e3ca1693a666c64 39: 0x7df2428a370a - <unknown> 40: 0x7df242927aac - <unknown> 41: 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: please make sure that you have updated to the latest nightly note: rustc 1.87.0-nightly (a96fa317d 2025-03-09) running on x86_64-unknown-linux-gnu note: compiler flags: -Z dump-mir=all -Z dump-mir-dir=dir query stack during panic: #0 [mir_built] building MIR for `{global_asm#0}` #1 [mir_promoted] promoting constants in MIR for `{global_asm#0}` #2 [mir_borrowck] borrow-checking `{global_asm#0}` #3 [analysis] running analysis passes on this crate end of query stack error: aborting due to 4 previous errors; 1 warning emitted Some errors have detailed explanations: E0425, E0601. For more information about an error, try `rustc --explain E0425`. 

Metadata

Metadata

Assignees

Labels

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