about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-15 14:11:55 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-15 14:11:55 -0800
commit9b7bc456ea7068fe6d24de995e083c3ea1e1ddaa (patch)
tree779763cb0fc6c9365f1ad46c7436facda387ce8e
parentb86a84867a31a04b9e9c35efc313b2961312def2 (diff)
parent31261fd629265aead5f0bdb45774067966896b1b (diff)
downloadrust-9b7bc456ea7068fe6d24de995e083c3ea1e1ddaa.tar.gz
rust-9b7bc456ea7068fe6d24de995e083c3ea1e1ddaa.zip
rollup merge of #21144: nagisa/asm-str-fix
Fixes #21045
-rw-r--r--src/libsyntax/ext/asm.rs6
-rw-r--r--src/test/compile-fail/issue-21045.rs16
2 files changed, 22 insertions, 0 deletions
diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs
index fd3bac5b2fc..4258eb32fdf 100644
--- a/src/libsyntax/ext/asm.rs
+++ b/src/libsyntax/ext/asm.rs
@@ -63,6 +63,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
     'statement: loop {
         match state {
             Asm => {
+                if asm_str_style.is_some() {
+                    // If we already have a string with instructions,
+                    // ending up in Asm state again is an error.
+                    cx.span_err(sp, "malformed inline assembly");
+                    return DummyResult::expr(sp);
+                }
                 let (s, style) = match expr_to_string(cx, p.parse_expr(),
                                                    "inline assembly must be a string literal") {
                     Some((s, st)) => (s, st),
diff --git a/src/test/compile-fail/issue-21045.rs b/src/test/compile-fail/issue-21045.rs
new file mode 100644
index 00000000000..134240f8c8a
--- /dev/null
+++ b/src/test/compile-fail/issue-21045.rs
@@ -0,0 +1,16 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+#![feature(asm)]
+
+fn main() {
+    let a;
+    asm!("nop" "nop"); //~ ERROR malformed inline assembly
+    asm!("nop" "nop" : "=r"(a)); //~ ERROR malformed inline assembly
+}