Skip to content

Commit f150ab3

Browse files
Improve code generating inline ASM
1 parent 5484c13 commit f150ab3

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/asm.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,10 @@ impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
706706
&& options.contains(InlineAsmOptions::ATT_SYNTAX);
707707

708708
// Build the template string
709-
let mut template_str = String::new();
709+
let mut template_str = ".pushsection .text\n".to_owned();
710+
if att_dialect {
711+
template_str.push_str(".att_syntax\n");
712+
}
710713
for piece in template {
711714
match *piece {
712715
InlineAsmTemplatePiece::String(ref string) => {
@@ -754,15 +757,11 @@ impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
754757
}
755758
}
756759

757-
let template_str =
758-
if att_dialect {
759-
format!(".att_syntax\n\t{}\n\t.intel_syntax noprefix", template_str)
760-
}
761-
else {
762-
template_str
763-
};
760+
if att_dialect {
761+
template_str.push_str("\n\t.intel_syntax noprefix");
762+
}
764763
// NOTE: seems like gcc will put the asm in the wrong section, so set it to .text manually.
765-
let template_str = format!(".pushsection .text\n{}\n.popsection", template_str);
764+
template_str.push_str("\n.popsection");
766765
self.context.add_top_level_asm(None, &template_str);
767766
}
768767
}

0 commit comments

Comments
 (0)