@@ -12,6 +12,7 @@ use rustc_codegen_ssa::traits::{
1212} ;
1313use rustc_middle:: bug;
1414use rustc_middle:: ty:: Instance ;
15+ use rustc_middle:: ty:: layout:: LayoutOf ;
1516use rustc_span:: Span ;
1617use rustc_target:: asm:: * ;
1718
@@ -303,8 +304,9 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
303304 }
304305 }
305306
306- InlineAsmOperandRef :: Const { ref string } => {
307- constants_len += string. len ( ) + att_dialect as usize ;
307+ InlineAsmOperandRef :: Const { .. } => {
308+ // We don't know the size at this point, just some estimate.
309+ constants_len += 20 ;
308310 }
309311
310312 InlineAsmOperandRef :: SymFn { instance } => {
@@ -453,7 +455,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
453455 template_str. push_str ( escaped_char) ;
454456 }
455457 }
456- InlineAsmTemplatePiece :: Placeholder { operand_idx, modifier, span : _ } => {
458+ InlineAsmTemplatePiece :: Placeholder { operand_idx, modifier, span } => {
457459 let mut push_to_template = |modifier, gcc_idx| {
458460 use std:: fmt:: Write ;
459461
@@ -511,8 +513,15 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
511513 template_str. push_str ( name) ;
512514 }
513515
514- InlineAsmOperandRef :: Const { ref string } => {
515- template_str. push_str ( string) ;
516+ InlineAsmOperandRef :: Const { value, ty } => {
517+ // Const operands get injected directly into the template
518+ let string = rustc_codegen_ssa:: common:: asm_const_to_str (
519+ self . tcx ,
520+ span,
521+ value,
522+ self . layout_of ( ty) ,
523+ ) ;
524+ template_str. push_str ( & string) ;
516525 }
517526
518527 InlineAsmOperandRef :: Label { label } => {
@@ -891,13 +900,19 @@ impl<'gcc, 'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
891900 . unwrap_or ( string. len ( ) ) ;
892901 }
893902 }
894- InlineAsmTemplatePiece :: Placeholder { operand_idx, modifier : _, span : _ } => {
903+ InlineAsmTemplatePiece :: Placeholder { operand_idx, modifier : _, span } => {
895904 match operands[ operand_idx] {
896- GlobalAsmOperandRef :: Const { ref string } => {
905+ GlobalAsmOperandRef :: Const { value , ty } => {
897906 // Const operands get injected directly into the
898907 // template. Note that we don't need to escape %
899908 // here unlike normal inline assembly.
900- template_str. push_str ( string) ;
909+ let string = rustc_codegen_ssa:: common:: asm_const_to_str (
910+ self . tcx ,
911+ span,
912+ value,
913+ self . layout_of ( ty) ,
914+ ) ;
915+ template_str. push_str ( & string) ;
901916 }
902917
903918 GlobalAsmOperandRef :: SymFn { instance } => {
0 commit comments