about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2022-10-18 23:11:46 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2022-10-18 23:11:46 +0200
commitf150ab3277c5ce2b154201e2205cd2e10cb8eb36 (patch)
treef624fade84a9b77009405296f58f9161431b19f6 /src
parent5484c131a5edbaee9a88bb4c7e9f14cced5afc8d (diff)
downloadrust-f150ab3277c5ce2b154201e2205cd2e10cb8eb36.tar.gz
rust-f150ab3277c5ce2b154201e2205cd2e10cb8eb36.zip
Improve code generating inline ASM
Diffstat (limited to 'src')
-rw-r--r--src/asm.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/asm.rs b/src/asm.rs
index 486c7a3f5cb..6dea20e4008 100644
--- a/src/asm.rs
+++ b/src/asm.rs
@@ -706,7 +706,10 @@ impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
             && options.contains(InlineAsmOptions::ATT_SYNTAX);
 
         // Build the template string
-        let mut template_str = String::new();
+        let mut template_str = ".pushsection .text\n".to_owned();
+        if att_dialect {
+            template_str.push_str(".att_syntax\n");
+        }
         for piece in template {
             match *piece {
                 InlineAsmTemplatePiece::String(ref string) => {
@@ -754,15 +757,11 @@ impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
             }
         }
 
-        let template_str =
-            if att_dialect {
-                format!(".att_syntax\n\t{}\n\t.intel_syntax noprefix", template_str)
-            }
-            else {
-                template_str
-            };
+        if att_dialect {
+            template_str.push_str("\n\t.intel_syntax noprefix");
+        }
         // NOTE: seems like gcc will put the asm in the wrong section, so set it to .text manually.
-        let template_str = format!(".pushsection .text\n{}\n.popsection", template_str);
+        template_str.push_str("\n.popsection");
         self.context.add_top_level_asm(None, &template_str);
     }
 }