Skip to content

Commit

Permalink
Exclude global_asm from mir_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 4, 2025
1 parent 4fdc1b5 commit dc9d559
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
// All body-owners have MIR associated with them.
let mut set: FxIndexSet<_> = tcx.hir_body_owners().collect();

// Remove the fake bodies for `global_asm!`, since they're not useful
// to be emitted (`--emit=mir`) or encoded (in metadata).
set.retain(|&def_id| !matches!(tcx.def_kind(def_id), DefKind::GlobalAsm));

// Coroutine-closures (e.g. async closures) have an additional by-move MIR
// body that isn't in the HIR.
for body_owner in tcx.hir_body_owners() {
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/asm/global-asm-isnt-really-a-mir-body.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ revisions: emit_mir instrument cfi

// Make sure we don't try to emit MIR for it.
//@[emit_mir] compile-flags: --emit=mir

// Make sure we don't try to instrument it.
//@[instrument] compile-flags: -Cinstrument-coverage -Zno-profiler-runtime
//@[instrument] only-linux

// Make sure we don't try to CFI encode it.
//@[cfi] compile-flags: -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Clink-dead-code=true
//@[cfi] needs-sanitizer-cfi
//@[cfi] no-prefer-dynamic

//@ build-pass

use std::arch::global_asm;

fn foo() {}

global_asm!("/* {} */", sym foo);

fn main() {}

0 comments on commit dc9d559

Please sign in to comment.