Skip to content

Commit 31261fd

Browse files
committed
Disallow a form of invalid asm! macro
Fixes #21045
1 parent f1241f1 commit 31261fd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/libsyntax/ext/asm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
6363
'statement: loop {
6464
match state {
6565
Asm => {
66+
if asm_str_style.is_some() {
67+
// If we already have a string with instructions,
68+
// ending up in Asm state again is an error.
69+
cx.span_err(sp, "malformed inline assembly");
70+
return DummyResult::expr(sp);
71+
}
6672
let (s, style) = match expr_to_string(cx, p.parse_expr(),
6773
"inline assembly must be a string literal") {
6874
Some((s, st)) => (s, st),

src/test/compile-fail/issue-21045.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(asm)]
11+
12+
fn main() {
13+
let a;
14+
asm!("nop" "nop"); //~ ERROR malformed inline assembly
15+
asm!("nop" "nop" : "=r"(a)); //~ ERROR malformed inline assembly
16+
}

0 commit comments

Comments
 (0)