Skip to content
/ rust Public
forked from rust-lang/rust

Commit 129b5bd

Browse files
authored
Rollup merge of rust-lang#137502 - compiler-errors:global-asm-aint-mir-body, r=oli-obk
Don't include global asm in `mir_keys`, fix error body synthesis r? oli-obk Fixes rust-lang#137470 Fixes rust-lang#137471 Fixes rust-lang#137472 Fixes rust-lang#137473 try-job: aarch64-apple
2 parents 41faffc + dc9d559 commit 129b5bd

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

compiler/rustc_mir_build/src/builder/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
612612
| DefKind::AssocConst
613613
| DefKind::AnonConst
614614
| DefKind::InlineConst
615-
| DefKind::Static { .. } => (vec![], tcx.type_of(def_id).instantiate_identity(), None),
615+
| DefKind::Static { .. }
616+
| DefKind::GlobalAsm => (vec![], tcx.type_of(def_id).instantiate_identity(), None),
616617
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => {
617618
let sig = tcx.liberate_late_bound_regions(
618619
def_id.to_def_id(),

compiler/rustc_mir_transform/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
316316
// All body-owners have MIR associated with them.
317317
let mut set: FxIndexSet<_> = tcx.hir_body_owners().collect();
318318

319+
// Remove the fake bodies for `global_asm!`, since they're not useful
320+
// to be emitted (`--emit=mir`) or encoded (in metadata).
321+
set.retain(|&def_id| !matches!(tcx.def_kind(def_id), DefKind::GlobalAsm));
322+
319323
// Coroutine-closures (e.g. async closures) have an additional by-move MIR
320324
// body that isn't in the HIR.
321325
for body_owner in tcx.hir_body_owners() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ revisions: emit_mir instrument cfi
2+
3+
// Make sure we don't try to emit MIR for it.
4+
//@[emit_mir] compile-flags: --emit=mir
5+
6+
// Make sure we don't try to instrument it.
7+
//@[instrument] compile-flags: -Cinstrument-coverage -Zno-profiler-runtime
8+
//@[instrument] only-linux
9+
10+
// Make sure we don't try to CFI encode it.
11+
//@[cfi] compile-flags: -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Clink-dead-code=true
12+
//@[cfi] needs-sanitizer-cfi
13+
//@[cfi] no-prefer-dynamic
14+
15+
//@ build-pass
16+
17+
use std::arch::global_asm;
18+
19+
fn foo() {}
20+
21+
global_asm!("/* {} */", sym foo);
22+
23+
fn main() {}

tests/ui/asm/global-asm-with-error.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Ensure that we don't ICE when constructing the fake MIR body for a global
2+
// asm when the body has errors. See #137470.
3+
4+
use std::arch::global_asm;
5+
6+
global_asm!("/* {} */", sym a);
7+
//~^ ERROR cannot find value `a` in this scope
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find value `a` in this scope
2+
--> $DIR/global-asm-with-error.rs:6:29
3+
|
4+
LL | global_asm!("/* {} */", sym a);
5+
| ^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)