]> git.lizzy.rs Git - rust.git/commitdiff
Fix ICE when using asm! on an unsupported architecture
authorAmanieu d'Antras <amanieu@gmail.com>
Thu, 6 Aug 2020 18:52:15 +0000 (19:52 +0100)
committerAmanieu d'Antras <amanieu@gmail.com>
Thu, 6 Aug 2020 18:52:15 +0000 (19:52 +0100)
Fixes #75220

src/librustc_ast_lowering/expr.rs
src/test/ui/asm/bad-arch.rs [new file with mode: 0644]
src/test/ui/asm/bad-arch.stderr [new file with mode: 0644]
src/test/ui/feature-gates/feature-gate-asm.rs
src/test/ui/feature-gates/feature-gate-asm2.rs

index abd5df537db99f14354b4ce904ab43d03cfc3e14..f9e54903a661acc6734bad331f7325360317b907 100644 (file)
@@ -1067,7 +1067,7 @@ fn lower_expr_asm(&mut self, sp: Span, asm: &InlineAsm) -> hir::ExprKind<'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 (file)
index 0000000..eeeeb17
--- /dev/null
@@ -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 (file)
index 0000000..daccc46
--- /dev/null
@@ -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
+
index 753e924f00495216de46d9094a7effa8a8552089..59f04372fff19218f45d30c178dde71c9349c31e 100644 (file)
@@ -1,4 +1,4 @@
-// ignore-emscripten
+// only-x86_64
 
 fn main() {
     unsafe {
index e9349acb64394e149b9682c9647e5405026ba4f4..aa63aff1c5e3384a3c80d65bf102211d1f45a173 100644 (file)
@@ -1,4 +1,4 @@
-// ignore-emscripten
+// only-x86_64
 
 fn main() {
     unsafe {