Skip to content

ICE: Unexpected def kind GlobalAsm #137471

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --emit=mir
core::arch::global_asm!(
    r#"
    .global foo
    .global _foo
foo:
_foo:
    ret
"#
);

fn main() {}

#[cfg(not)]
fn main() {}

original:

//@ run-pass
//@ needs-asm-support

#![feature(naked_functions)]
#![allow(dead_code)]

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
core::arch::global_asm!(
    r#"
    .global foo
    .global _foo
foo:
_foo:
    ret
"#
);

extern "C" {
    fn foo();
}

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
fn main() {
    unsafe {
        foo();
    }
}

#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
fn main() {}

This worked before #137180

Version information

rustc 1.87.0-nightly (bca5f37cb 2025-02-23)
binary: rustc
commit-hash: bca5f37cbded0db8d37414bb08c4b101a5f26d36
commit-date: 2025-02-23
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 --emit=mir

Program output

error: internal compiler error: compiler/rustc_middle/src/mir/pretty.rs:656:14: Unexpected def kind GlobalAsm


thread 'rustc' panicked at compiler/rustc_middle/src/mir/pretty.rs:656:14:
Box<dyn Any>
stack backtrace:
   0:     0x72dabd57d024 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hb2766718346e8914
   1:     0x72dabdc162ec - core::fmt::write::h9a1616cb06c0cb0c
   2:     0x72dabec69851 - std::io::Write::write_fmt::ha495c1f1db9a43ed
   3:     0x72dabd57ce82 - std::sys::backtrace::BacktraceLock::print::hfcfc21e91f78122e
   4:     0x72dabd57f68e - std::panicking::default_hook::{{closure}}::hdbc3741f9d3f7a84
   5:     0x72dabd57f264 - std::panicking::default_hook::hc24bc002e7741aa1
   6:     0x72dabc6de2d7 - std[aff040118bb958da]::panicking::update_hook::<alloc[67af6a9cecfd7ba8]::boxed::Box<rustc_driver_impl[301a9b8b79b48566]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x72dabd57ff03 - std::panicking::rust_panic_with_hook::hcb6606e9e0388155
   8:     0x72dabc719bd1 - std[aff040118bb958da]::panicking::begin_panic::<rustc_errors[ccf3a74766137fa5]::ExplicitBug>::{closure#0}
   9:     0x72dabc70dfe6 - std[aff040118bb958da]::sys::backtrace::__rust_end_short_backtrace::<std[aff040118bb958da]::panicking::begin_panic<rustc_errors[ccf3a74766137fa5]::ExplicitBug>::{closure#0}, !>
  10:     0x72dabc70dfcb - std[aff040118bb958da]::panicking::begin_panic::<rustc_errors[ccf3a74766137fa5]::ExplicitBug>
  11:     0x72dabc7235d1 - <rustc_errors[ccf3a74766137fa5]::diagnostic::BugAbort as rustc_errors[ccf3a74766137fa5]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x72dabccf4846 - rustc_middle[bff44984932adf4f]::util::bug::opt_span_bug_fmt::<rustc_span[2a04d5a35653b919]::span_encoding::Span>::{closure#0}
  13:     0x72dabccddd2a - rustc_middle[bff44984932adf4f]::ty::context::tls::with_opt::<rustc_middle[bff44984932adf4f]::util::bug::opt_span_bug_fmt<rustc_span[2a04d5a35653b919]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x72dabccddb9b - rustc_middle[bff44984932adf4f]::ty::context::tls::with_context_opt::<rustc_middle[bff44984932adf4f]::ty::context::tls::with_opt<rustc_middle[bff44984932adf4f]::util::bug::opt_span_bug_fmt<rustc_span[2a04d5a35653b919]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x72dabb0f9e20 - rustc_middle[bff44984932adf4f]::util::bug::bug_fmt
  16:     0x72dabccb5fc5 - rustc_middle[bff44984932adf4f]::mir::pretty::write_mir_intro
  17:     0x72dabccb1ace - rustc_middle[bff44984932adf4f]::mir::pretty::write_mir_pretty::{closure#0}
  18:     0x72dabccb0668 - rustc_middle[bff44984932adf4f]::mir::pretty::write_mir_pretty
  19:     0x72dabce9783c - rustc_mir_transform[235952b1afe2fde9]::dump_mir::emit_mir
  20:     0x72dabeabae05 - <rustc_interface[a6a17d2a4de965ee]::queries::Linker>::codegen_and_build_linker
  21:     0x72dabed4e1ef - rustc_interface[a6a17d2a4de965ee]::passes::create_and_enter_global_ctxt::<core[25dd51937c36d244]::option::Option<rustc_interface[a6a17d2a4de965ee]::queries::Linker>, rustc_driver_impl[301a9b8b79b48566]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  22:     0x72dabed41a60 - rustc_interface[a6a17d2a4de965ee]::interface::run_compiler::<(), rustc_driver_impl[301a9b8b79b48566]::run_compiler::{closure#0}>::{closure#1}
  23:     0x72dabeb7eedc - std[aff040118bb958da]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a6a17d2a4de965ee]::util::run_in_thread_with_globals<rustc_interface[a6a17d2a4de965ee]::util::run_in_thread_pool_with_globals<rustc_interface[a6a17d2a4de965ee]::interface::run_compiler<(), rustc_driver_impl[301a9b8b79b48566]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  24:     0x72dabeb7f300 - <<std[aff040118bb958da]::thread::Builder>::spawn_unchecked_<rustc_interface[a6a17d2a4de965ee]::util::run_in_thread_with_globals<rustc_interface[a6a17d2a4de965ee]::util::run_in_thread_pool_with_globals<rustc_interface[a6a17d2a4de965ee]::interface::run_compiler<(), rustc_driver_impl[301a9b8b79b48566]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[25dd51937c36d244]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x72dabeb7fceb - std::sys::pal::unix::thread::Thread::new::thread_start::h4bc285b173c402c8
  26:     0x72dab8ea370a - <unknown>
  27:     0x72dab8f27aac - <unknown>
  28:                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 (bca5f37cb 2025-02-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
end of query stack
error: aborting due to 1 previous error


@rustbot label +F-naked_functions

Metadata

Metadata

Labels

A-prettyArea: Pretty printing (including `-Z unpretty`)C-bugCategory: This is a bug.F-naked_functions`#![feature(naked_functions)]`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.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions