]> git.lizzy.rs Git - rust.git/commitdiff
Check if output is immediate value
authorYuki Okushi <huyuumi.dev@gmail.com>
Sun, 8 Mar 2020 20:00:03 +0000 (05:00 +0900)
committerYuki Okushi <huyuumi.dev@gmail.com>
Sun, 8 Mar 2020 22:48:08 +0000 (07:48 +0900)
src/librustc_codegen_llvm/asm.rs
src/test/ui/asm/issue-62046.rs [new file with mode: 0644]
src/test/ui/asm/issue-62046.stderr [new file with mode: 0644]

index c8f0fe8c7239558ea75b30eb47a3b6a1f2a0bed3..7975a70ab269c9d40ff0bcb69c8c9156a7b08e8c 100644 (file)
@@ -29,11 +29,17 @@ fn codegen_inline_asm(
         let mut indirect_outputs = vec![];
         for (i, (out, &place)) in ia.outputs.iter().zip(&outputs).enumerate() {
             if out.is_rw {
-                inputs.push(self.load_operand(place).immediate());
+                let operand = self.load_operand(place);
+                if let OperandValue::Immediate(_) = operand.val {
+                    inputs.push(operand.immediate());
+                }
                 ext_constraints.push(i.to_string());
             }
             if out.is_indirect {
-                indirect_outputs.push(self.load_operand(place).immediate());
+                let operand = self.load_operand(place);
+                if let OperandValue::Immediate(_) = operand.val {
+                    indirect_outputs.push(operand.immediate());
+                }
             } else {
                 output_types.push(place.layout.llvm_type(self.cx()));
             }
diff --git a/src/test/ui/asm/issue-62046.rs b/src/test/ui/asm/issue-62046.rs
new file mode 100644 (file)
index 0000000..105dadd
--- /dev/null
@@ -0,0 +1,11 @@
+// build-fail
+// ignore-emscripten no asm! support
+
+#![feature(asm)]
+
+fn main() {
+    unsafe {
+        asm!("nop" : "+r"("r15"));
+        //~^ malformed inline assembly
+    }
+}
diff --git a/src/test/ui/asm/issue-62046.stderr b/src/test/ui/asm/issue-62046.stderr
new file mode 100644 (file)
index 0000000..a38a300
--- /dev/null
@@ -0,0 +1,11 @@
+error[E0668]: malformed inline assembly
+  --> $DIR/issue-62046.rs:8:9
+   |
+LL |         asm!("nop" : "+r"("r15"));
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0668`.