@@ -438,58 +438,50 @@ static void EmitKill(const MachineInstr *MI, AsmPrinter &AP) {
438
438
// / of DBG_VALUE, returning true if it was able to do so. A false return
439
439
// / means the target will need to handle MI in EmitInstruction.
440
440
static bool EmitDebugValueComment (const MachineInstr *MI, AsmPrinter &AP) {
441
- char buf[100 ];
442
- std::string Str = " \t " ;
443
- Str += AP.MAI ->getCommentString ();
444
- Str += " DEBUG_VALUE: " ;
445
441
// This code handles only the 3-operand target-independent form.
446
442
if (MI->getNumOperands () != 3 )
447
443
return false ;
448
444
445
+ SmallString<128 > Str;
446
+ raw_svector_ostream OS (Str);
447
+ OS << ' \t ' << AP.MAI ->getCommentString () << " DEBUG_VALUE: " ;
448
+
449
449
// cast away const; DIetc do not take const operands for some reason.
450
450
DIVariable V ((MDNode*)(MI->getOperand (2 ).getMetadata ()));
451
- Str += V.getName ();
452
- Str += " <- " ;
451
+ OS << V.getName () << " <- " ;
453
452
454
453
// Register or immediate value. Register 0 means undef.
455
454
if (MI->getOperand (0 ).isFPImm ()) {
456
455
APFloat APF = APFloat (MI->getOperand (0 ).getFPImm ()->getValueAPF ());
457
456
if (MI->getOperand (0 ).getFPImm ()->getType ()->isFloatTy ()) {
458
- sprintf (buf, " %e" , APF.convertToFloat ());
459
- Str += buf;
457
+ OS << (double )APF.convertToFloat ();
460
458
} else if (MI->getOperand (0 ).getFPImm ()->getType ()->isDoubleTy ()) {
461
- sprintf (buf, " %e" , APF.convertToDouble ());
462
- Str += buf;
459
+ OS << APF.convertToDouble ();
463
460
} else {
464
461
// There is no good way to print long double. Convert a copy to
465
462
// double. Ah well, it's only a comment.
466
463
bool ignored;
467
464
APF.convert (APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
468
465
&ignored);
469
- Str += " (long double) " ;
470
- sprintf (buf, " %e" , APF.convertToDouble ());
471
- Str += buf;
466
+ OS << " (long double) " << APF.convertToDouble ();
472
467
}
473
468
} else if (MI->getOperand (0 ).isImm ()) {
474
- sprintf (buf, " %lld" , MI->getOperand (0 ).getImm ());
475
- Str += buf;
469
+ OS << MI->getOperand (0 ).getImm ();
476
470
} else if (MI->getOperand (0 ).isReg ()) {
477
471
if (MI->getOperand (0 ).getReg () == 0 ) {
478
472
// Suppress offset, it is not meaningful here.
479
- Str += " undef" ;
473
+ OS << " undef" ;
480
474
// NOTE: Want this comment at start of line, don't emit with AddComment.
481
- AP.OutStreamer .EmitRawText (Twine (Str ));
475
+ AP.OutStreamer .EmitRawText (OS. str ( ));
482
476
return true ;
483
477
}
484
- Str += AP.TM .getRegisterInfo ()->getName (MI->getOperand (0 ).getReg ());
478
+ OS << AP.TM .getRegisterInfo ()->getName (MI->getOperand (0 ).getReg ());
485
479
} else
486
480
llvm_unreachable (" Unknown operand type" );
487
481
488
- Str += ' +' ;
489
- sprintf (buf, " %lld" , MI->getOperand (1 ).getImm ());
490
- Str += buf;
482
+ OS << ' +' << MI->getOperand (1 ).getImm ();
491
483
// NOTE: Want this comment at start of line, don't emit with AddComment.
492
- AP.OutStreamer .EmitRawText (Twine (Str ));
484
+ AP.OutStreamer .EmitRawText (OS. str ( ));
493
485
return true ;
494
486
}
495
487
0 commit comments