Skip to content

Commit 15fcca8

Browse files
committed
Escape { and } in inline asm
1 parent bfc184c commit 15fcca8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/asm.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,19 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
381381
for piece in template {
382382
match *piece {
383383
InlineAsmTemplatePiece::String(ref string) => {
384-
// TODO(@Commeownist): switch to `Iterator::intersperse` once it's stable
385-
let mut iter = string.split('%');
386-
if let Some(s) = iter.next() {
387-
template_str.push_str(s);
388-
}
389-
390-
for s in iter {
391-
template_str.push_str("%%");
392-
template_str.push_str(s);
384+
for char in string.chars() {
385+
// TODO(antoyo): might also need to escape | if rustc doesn't do it.
386+
let escaped_char =
387+
match char {
388+
'%' => "%%",
389+
'{' => "%{",
390+
'}' => "%}",
391+
_ => {
392+
template_str.push(char);
393+
continue;
394+
},
395+
};
396+
template_str.push_str(escaped_char);
393397
}
394398
}
395399
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier, span: _ } => {

0 commit comments

Comments
 (0)