about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2020-05-26 20:07:59 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2020-05-29 17:05:35 +0100
commitb78b15665b622cc37b25e9bd971537296403b83d (patch)
tree63e4aaed856ebbf244ac375b18e421ecc3083381 /src/test
parent96dd4690c3aa70ec312448c3f2d50e6dc6fb87df (diff)
downloadrust-b78b15665b622cc37b25e9bd971537296403b83d.tar.gz
rust-b78b15665b622cc37b25e9bd971537296403b83d.zip
Improve inline asm error diagnostics
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/asm/srcloc.rs41
-rw-r--r--src/test/ui/asm/srcloc.stderr74
-rw-r--r--src/test/ui/issues/issue-23458.stderr15
-rw-r--r--src/test/ui/llvm-asm/issue-69092.rs2
-rw-r--r--src/test/ui/llvm-asm/issue-69092.stderr13
5 files changed, 133 insertions, 12 deletions
diff --git a/src/test/ui/asm/srcloc.rs b/src/test/ui/asm/srcloc.rs
new file mode 100644
index 00000000000..7af6f620a98
--- /dev/null
+++ b/src/test/ui/asm/srcloc.rs
@@ -0,0 +1,41 @@
+// no-system-llvm
+// only-x86_64
+// build-fail
+
+#![feature(asm)]
+
+// Checks that inline asm errors are mapped to the correct line in the source code.
+
+fn main() {
+    unsafe {
+        asm!("invalid_instruction");
+        //~^ ERROR: invalid instruction mnemonic 'invalid_instruction'
+
+        asm!("
+            invalid_instruction
+        ");
+        //~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
+
+        asm!(r#"
+            invalid_instruction
+        "#);
+        //~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
+
+        asm!("
+            mov eax, eax
+            invalid_instruction
+            mov eax, eax
+        ");
+        //~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
+
+        asm!(r#"
+            mov eax, eax
+            invalid_instruction
+            mov eax, eax
+        "#);
+        //~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
+
+        asm!(concat!("invalid", "_", "instruction"));
+        //~^ ERROR: invalid instruction mnemonic 'invalid_instruction'
+    }
+}
diff --git a/src/test/ui/asm/srcloc.stderr b/src/test/ui/asm/srcloc.stderr
new file mode 100644
index 00000000000..57a4fbb9742
--- /dev/null
+++ b/src/test/ui/asm/srcloc.stderr
@@ -0,0 +1,74 @@
+error: invalid instruction mnemonic 'invalid_instruction'
+  --> $DIR/srcloc.rs:11:15
+   |
+LL |         asm!("invalid_instruction");
+   |               ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:2:2
+   |
+LL |     invalid_instruction
+   |     ^^^^^^^^^^^^^^^^^^^
+
+error: invalid instruction mnemonic 'invalid_instruction'
+  --> $DIR/srcloc.rs:15:13
+   |
+LL |             invalid_instruction
+   |             ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:3:13
+   |
+LL |             invalid_instruction
+   |             ^^^^^^^^^^^^^^^^^^^
+
+error: invalid instruction mnemonic 'invalid_instruction'
+  --> $DIR/srcloc.rs:20:13
+   |
+LL |             invalid_instruction
+   |             ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:3:13
+   |
+LL |             invalid_instruction
+   |             ^^^^^^^^^^^^^^^^^^^
+
+error: invalid instruction mnemonic 'invalid_instruction'
+  --> $DIR/srcloc.rs:26:13
+   |
+LL |             invalid_instruction
+   |             ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:4:13
+   |
+LL |             invalid_instruction
+   |             ^^^^^^^^^^^^^^^^^^^
+
+error: invalid instruction mnemonic 'invalid_instruction'
+  --> $DIR/srcloc.rs:33:13
+   |
+LL |             invalid_instruction
+   |             ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:4:13
+   |
+LL |             invalid_instruction
+   |             ^^^^^^^^^^^^^^^^^^^
+
+error: invalid instruction mnemonic 'invalid_instruction'
+  --> $DIR/srcloc.rs:38:14
+   |
+LL |         asm!(concat!("invalid", "_", "instruction"));
+   |              ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:2:2
+   |
+LL |     invalid_instruction
+   |     ^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 6 previous errors
+
diff --git a/src/test/ui/issues/issue-23458.stderr b/src/test/ui/issues/issue-23458.stderr
index 81f06e63975..a6500b9bb4c 100644
--- a/src/test/ui/issues/issue-23458.stderr
+++ b/src/test/ui/issues/issue-23458.stderr
@@ -2,16 +2,19 @@ error: invalid operand in inline asm: 'int $3'
   --> $DIR/issue-23458.rs:8:9
    |
 LL |         llvm_asm!("int $3");
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-error: <inline asm>:1:2: error: too few operands for instruction
-        int 
-        ^
+   |         ^
 
+error: too few operands for instruction
   --> $DIR/issue-23458.rs:8:9
    |
 LL |         llvm_asm!("int $3");
-   |         ^^^^^^^^^^^^^^^^^^^^
+   |         ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:1:2
+   |
+LL |     int 
+   |     ^
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/llvm-asm/issue-69092.rs b/src/test/ui/llvm-asm/issue-69092.rs
index ecce7bfdf5b..96c019b760e 100644
--- a/src/test/ui/llvm-asm/issue-69092.rs
+++ b/src/test/ui/llvm-asm/issue-69092.rs
@@ -6,5 +6,5 @@
 
 fn main() {
     unsafe { llvm_asm!(".ascii \"Xen\0\""); }
-    //~^ ERROR: <inline asm>:1:9: error: expected string in '.ascii' directive
+    //~^ ERROR: expected string in '.ascii' directive
 }
diff --git a/src/test/ui/llvm-asm/issue-69092.stderr b/src/test/ui/llvm-asm/issue-69092.stderr
index 35f77edc3c4..2ca86cf7c1b 100644
--- a/src/test/ui/llvm-asm/issue-69092.stderr
+++ b/src/test/ui/llvm-asm/issue-69092.stderr
@@ -1,11 +1,14 @@
-error: <inline asm>:1:9: error: expected string in '.ascii' directive
-        .ascii "Xen
-               ^
-
+error: expected string in '.ascii' directive
   --> $DIR/issue-69092.rs:8:14
    |
 LL |     unsafe { llvm_asm!(".ascii \"Xen\0\""); }
-   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |              ^
+   |
+note: instantiated into assembly here
+  --> <inline asm>:1:9
+   |
+LL |     .ascii "Xen
+   |            ^
 
 error: aborting due to previous error