Package: rustc / 1.46.0+dfsg1-1

u-9abdb6db6f7d50761a701fe17d384d7ea49b015d.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From 9abdb6db6f7d50761a701fe17d384d7ea49b015d Mon Sep 17 00:00:00 2001
From: Amanieu d'Antras <amanieu@gmail.com>
Date: Thu, 6 Aug 2020 19:52:15 +0100
Subject: [PATCH] Fix ICE when using asm! on an unsupported architecture

Fixes #75220
---
 src/librustc_ast_lowering/expr.rs              |  2 +-
 src/test/ui/asm/bad-arch.rs                    | 18 ++++++++++++++++++
 src/test/ui/asm/bad-arch.stderr                |  8 ++++++++
 src/test/ui/feature-gates/feature-gate-asm.rs  |  2 +-
 src/test/ui/feature-gates/feature-gate-asm2.rs |  2 +-
 5 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 src/test/ui/asm/bad-arch.rs
 create mode 100644 src/test/ui/asm/bad-arch.stderr

diff --git a/src/librustc_ast_lowering/expr.rs b/src/librustc_ast_lowering/expr.rs
index abd5df537db99..f9e54903a661a 100644
--- a/src/librustc_ast_lowering/expr.rs
+++ b/src/librustc_ast_lowering/expr.rs
@@ -1067,7 +1067,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
             .collect();
 
         // Stop if there were any errors when lowering the register classes
-        if operands.len() != asm.operands.len() {
+        if operands.len() != asm.operands.len() || sess.asm_arch.is_none() {
             return hir::ExprKind::Err;
         }
 
diff --git a/src/test/ui/asm/bad-arch.rs b/src/test/ui/asm/bad-arch.rs
new file mode 100644
index 0000000000000..eeeeb17dd4f3f
--- /dev/null
+++ b/src/test/ui/asm/bad-arch.rs
@@ -0,0 +1,18 @@
+// compile-flags: --target wasm32-unknown-unknown
+
+#![feature(no_core, lang_items, rustc_attrs)]
+#![no_core]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+    () => {};
+}
+#[lang = "sized"]
+trait Sized {}
+
+fn main() {
+    unsafe {
+        asm!("");
+        //~^ ERROR asm! is unsupported on this target
+    }
+}
diff --git a/src/test/ui/asm/bad-arch.stderr b/src/test/ui/asm/bad-arch.stderr
new file mode 100644
index 0000000000000..daccc46c6e371
--- /dev/null
+++ b/src/test/ui/asm/bad-arch.stderr
@@ -0,0 +1,8 @@
+error[E0472]: asm! is unsupported on this target
+  --> $DIR/bad-arch.rs:15:9
+   |
+LL |         asm!("");
+   |         ^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/feature-gates/feature-gate-asm.rs b/src/test/ui/feature-gates/feature-gate-asm.rs
index 753e924f00495..59f04372fff19 100644
--- a/src/test/ui/feature-gates/feature-gate-asm.rs
+++ b/src/test/ui/feature-gates/feature-gate-asm.rs
@@ -1,4 +1,4 @@
-// ignore-emscripten
+// only-x86_64
 
 fn main() {
     unsafe {
diff --git a/src/test/ui/feature-gates/feature-gate-asm2.rs b/src/test/ui/feature-gates/feature-gate-asm2.rs
index e9349acb64394..aa63aff1c5e33 100644
--- a/src/test/ui/feature-gates/feature-gate-asm2.rs
+++ b/src/test/ui/feature-gates/feature-gate-asm2.rs
@@ -1,4 +1,4 @@
-// ignore-emscripten
+// only-x86_64
 
 fn main() {
     unsafe {