diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index f880b1364c2cd..05da8511361cd 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -653,7 +653,10 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io: write!(w, "static mut ")? } (_, _) if is_function => write!(w, "fn ")?, - (DefKind::AnonConst | DefKind::InlineConst, _) => {} // things like anon const, not an item + // things like anon const, not an item + (DefKind::AnonConst | DefKind::InlineConst, _) => {} + // `global_asm!` have fake bodies, which we may dump after mir-build + (DefKind::GlobalAsm, _) => {} _ => bug!("Unexpected def kind {:?}", kind), } diff --git a/tests/mir-opt/global_asm.rs b/tests/mir-opt/global_asm.rs new file mode 100644 index 0000000000000..22b782d365e94 --- /dev/null +++ b/tests/mir-opt/global_asm.rs @@ -0,0 +1,9 @@ +// skip-filecheck +//@ needs-asm-support + +// `global_asm!` gets a fake body, make sure it is handled correctly + +// EMIT_MIR global_asm.{global_asm#0}.SimplifyLocals-final.after.mir +core::arch::global_asm!("/* */"); + +fn main() {} diff --git a/tests/mir-opt/global_asm.{global_asm#0}.SimplifyLocals-final.after.mir b/tests/mir-opt/global_asm.{global_asm#0}.SimplifyLocals-final.after.mir new file mode 100644 index 0000000000000..cec3c4a8261e6 --- /dev/null +++ b/tests/mir-opt/global_asm.{global_asm#0}.SimplifyLocals-final.after.mir @@ -0,0 +1,9 @@ +// MIR for `{global_asm#0}` after SimplifyLocals-final + +{global_asm#0}: ! = { + let mut _0: !; + + bb0: { + asm!("/* */", options()) -> unwind unreachable; + } +}