Auto merge of #137502 - compiler-errors:global-asm-aint-mir-body, r=o… · rust-lang/rust@dea1661 (original) (raw)
File tree
6 files changed
lines changed
- rustc_mir_build/src/builder
6 files changed
lines changed
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
@@ -612,7 +612,8 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) - | |||
612 | 612 | | DefKind::AssocConst | |
613 | 613 | | DefKind::AnonConst | |
614 | 614 | | 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), | ||
616 | 617 | DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => { |
617 | 618 | let sig = tcx.liberate_late_bound_regions( | |
618 | 619 | def_id.to_def_id(), |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -316,6 +316,10 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet { | ||
316 | 316 | // All body-owners have MIR associated with them. |
317 | 317 | let mut set: FxIndexSet<_> = tcx.hir_body_owners().collect(); |
318 | 318 | |
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 | |
322 | + | |
319 | 323 | // Coroutine-closures (e.g. async closures) have an additional by-move MIR |
320 | 324 | // body that isn't in the HIR. |
321 | 325 | for body_owner in tcx.hir_body_owners() { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -12,7 +12,7 @@ use std::arch::x86_64::*; | ||
12 | 12 | #[cfg(target_arch = "x86_64")] |
13 | 13 | #[target_feature(enable = "avx")] |
14 | 14 | fn with_avx(x: __m256) -> __m256 { |
15 | -// CHECK: fadd | |
15 | +// CHECK: fadd <8 x float> | |
16 | 16 | let add = { |
17 | 17 | #[inline(always)] |
18 | 18 | |x, y |
@@ -24,14 +24,10 @@ fn with_avx(x: __m256) -> __m256 { | ||
24 | 24 | #[no_mangle] |
25 | 25 | #[cfg(target_arch = "x86_64")] |
26 | 26 | unsafe fn without_avx(x: __m256) -> __m256 { |
27 | -// CHECK-NOT: fadd | |
27 | +// CHECK-NOT: fadd <8 x float> | |
28 | 28 | let add = { |
29 | 29 | #[inline(always)] |
30 | 30 | |x, y |
31 | 31 | }; |
32 | 32 | add(x, x) |
33 | 33 | } |
34 | - | |
35 | -// Don't allow the above CHECK-NOT to accidentally match a commit hash in the | |
36 | -// compiler version. | |
37 | -// CHECK-LABEL: rustc version |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 -Ctarget-feature=-crt-static -Clink-dead-code=true | |
12 | +//@[cfi] needs-sanitizer-cfi | |
13 | +//@[cfi] no-prefer-dynamic | |
14 | +// FIXME(#122848) Remove only-linux once OSX CFI binaries work | |
15 | +//@[cfi] only-linux | |
16 | + | |
17 | +//@ build-pass | |
18 | +//@ needs-asm-support | |
19 | + | |
20 | +use std::arch::global_asm; | |
21 | + | |
22 | +fn foo() {} | |
23 | + | |
24 | +global_asm!("/* {} */", sym foo); | |
25 | + | |
26 | +fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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 | +//@ needs-asm-support | |
5 | + | |
6 | +use std::arch::global_asm; | |
7 | + | |
8 | +global_asm!("/* {} */", sym a); | |
9 | +//~^ ERROR cannot find value `a` in this scope | |
10 | + | |
11 | +fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
1 | +error[E0425]: cannot find value `a` in this scope | |
2 | + --> $DIR/global-asm-with-error.rs:8: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`. |