about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorantoyo <antoyo@users.noreply.github.com>2022-11-24 13:54:59 -0500
committerGitHub <noreply@github.com>2022-11-24 13:54:59 -0500
commit3c03c8f0484ffea08fb760c8cdee97befe3eb83a (patch)
tree4e5c90384329539006adb4b65ab02eb1041cff12 /src
parentbfc184cd2c6baaba01f72bc11be2f0af3c21b236 (diff)
parent15fcca80a40e2e9bfc658b6a98bfb9856d122d14 (diff)
downloadrust-3c03c8f0484ffea08fb760c8cdee97befe3eb83a.tar.gz
rust-3c03c8f0484ffea08fb760c8cdee97befe3eb83a.zip
Merge pull request #239 from rust-lang/fix/expandloadu
Escape { and } in inline asm
Diffstat (limited to 'src')
-rw-r--r--src/asm.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/asm.rs b/src/asm.rs
index 6dea20e4008..0d5c343ffe3 100644
--- a/src/asm.rs
+++ b/src/asm.rs
@@ -381,15 +381,19 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
         for piece in template {
             match *piece {
                 InlineAsmTemplatePiece::String(ref string) => {
-                    // TODO(@Commeownist): switch to `Iterator::intersperse` once it's stable
-                    let mut iter = string.split('%');
-                    if let Some(s) = iter.next() {
-                        template_str.push_str(s);
-                    }
-
-                    for s in iter {
-                        template_str.push_str("%%");
-                        template_str.push_str(s);
+                    for char in string.chars() {
+                        // TODO(antoyo): might also need to escape | if rustc doesn't do it.
+                        let escaped_char =
+                            match char {
+                                '%' => "%%",
+                                '{' => "%{",
+                                '}' => "%}",
+                                _ => {
+                                    template_str.push(char);
+                                    continue;
+                                },
+                            };
+                        template_str.push_str(escaped_char);
                     }
                 }
                 InlineAsmTemplatePiece::Placeholder { operand_idx, modifier, span: _ } => {