Skip to content

Commit 989f906

Browse files
committed
syntax: Make asm! clobbers a proper vector.
Otherwise `--pretty expanded` diverges.
1 parent 8d8f41b commit 989f906

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

src/librustc_trans/trans/asm.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,18 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
8585
.connect(",")
8686
.as_slice());
8787

88-
let mut clobbers = get_clobbers();
89-
if !ia.clobbers.get().is_empty() && !clobbers.is_empty() {
90-
clobbers = format!("{},{}", ia.clobbers.get(), clobbers);
91-
} else {
92-
clobbers.push_str(ia.clobbers.get());
88+
let mut clobbers =
89+
String::from_str(ia.clobbers.iter()
90+
.map(|s| format!("~{{{}}}", s.get()))
91+
.collect::<Vec<String>>()
92+
.connect(",")
93+
.as_slice());
94+
let more_clobbers = get_clobbers();
95+
if !more_clobbers.is_empty() {
96+
if !clobbers.is_empty() {
97+
clobbers.push(',');
98+
}
99+
clobbers.push_str(more_clobbers.as_slice());
93100
}
94101

95102
// Add the clobbers to our constraints list

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ pub struct InlineAsm {
11771177
pub asm_str_style: StrStyle,
11781178
pub outputs: Vec<(InternedString, P<Expr>, bool)>,
11791179
pub inputs: Vec<(InternedString, P<Expr>)>,
1180-
pub clobbers: InternedString,
1180+
pub clobbers: Vec<InternedString>,
11811181
pub volatile: bool,
11821182
pub alignstack: bool,
11831183
pub dialect: AsmDialect,

src/libsyntax/ext/asm.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
5353
let mut asm_str_style = None;
5454
let mut outputs = Vec::new();
5555
let mut inputs = Vec::new();
56-
let mut cons = "".to_string();
56+
let mut clobs = Vec::new();
5757
let mut volatile = false;
5858
let mut alignstack = false;
5959
let mut dialect = ast::AsmAtt;
@@ -138,7 +138,6 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
138138
}
139139
}
140140
Clobbers => {
141-
let mut clobs = Vec::new();
142141
while p.token != token::Eof &&
143142
p.token != token::Colon &&
144143
p.token != token::ModSep {
@@ -148,15 +147,12 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
148147
}
149148

150149
let (s, _str_style) = p.parse_str();
151-
let clob = format!("~{{{}}}", s);
152-
clobs.push(clob);
153150

154151
if OPTIONS.iter().any(|opt| s.equiv(opt)) {
155152
cx.span_warn(p.last_span, "expected a clobber, found an option");
156153
}
154+
clobs.push(s);
157155
}
158-
159-
cons = clobs.connect(",");
160156
}
161157
Options => {
162158
let (option, _str_style) = p.parse_str();
@@ -216,7 +212,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
216212
asm_str_style: asm_str_style.unwrap(),
217213
outputs: outputs,
218214
inputs: inputs,
219-
clobbers: token::intern_and_get_ident(cons.as_slice()),
215+
clobbers: clobs,
220216
volatile: volatile,
221217
alignstack: alignstack,
222218
dialect: dialect,

src/libsyntax/print/pprust.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,11 @@ impl<'a> State<'a> {
18391839
try!(space(&mut self.s));
18401840
try!(self.word_space(":"));
18411841

1842-
try!(self.print_string(a.clobbers.get(), ast::CookedStr));
1842+
try!(self.commasep(Inconsistent, a.clobbers.as_slice(),
1843+
|s, co| {
1844+
try!(s.print_string(co.get(), ast::CookedStr));
1845+
Ok(())
1846+
}));
18431847
try!(self.pclose());
18441848
}
18451849
ast::ExprMac(ref m) => try!(self.print_mac(m)),

src/test/pretty/asm-clobbers.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
11+
#![feature(asm)]
12+
13+
pub fn main() { unsafe { asm!("" : : : "hello", "world") }; }
14+

0 commit comments

Comments
 (0)