summaryrefslogtreecommitdiff
path: root/lib/CodeGen/AsmPrinter
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-06-26 00:00:48 +0000
committerAlp Toker <alp@nuanti.com>2014-06-26 00:00:48 +0000
commit255907042245b77779e3e38c5ce66901866cabe5 (patch)
tree92db65aa99c37ab5f68cd6adaae1d8cf6d629b8f /lib/CodeGen/AsmPrinter
parentce6e7c7a59e8595ea3f30d87cbad4af278cb5ef3 (diff)
downloadllvm-255907042245b77779e3e38c5ce66901866cabe5.tar.gz
llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.bz2
llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.xz
Introduce a string_ostream string builder facilty
string_ostream is a safe and efficient string builder that combines opaque stack storage with a built-in ostream interface. small_string_ostream<bytes> additionally permits an explicit stack storage size other than the default 128 bytes to be provided. Beyond that, storage is transferred to the heap. This convenient class can be used in most places an std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair would previously have been used, in order to guarantee consistent access without byte truncation. The patch also converts much of LLVM to use the new facility. These changes include several probable bug fixes for truncated output, a programming error that's no longer possible with the new interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211749 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/AsmPrinter')
-rw-r--r--lib/CodeGen/AsmPrinter/AsmPrinter.cpp3
-rw-r--r--lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp12
2 files changed, 5 insertions, 10 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 799ee92d3a..ebb49c34a7 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1585,8 +1585,7 @@ static const MCExpr *lowerConstant(const Constant *CV, AsmPrinter &AP) {
// Otherwise report the problem to the user.
{
- std::string S;
- raw_string_ostream OS(S);
+ string_ostream OS;
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 46ee0c856b..01f26d0c4c 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -241,8 +241,7 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
}
}
if (Error) {
- std::string msg;
- raw_string_ostream Msg(msg);
+ string_ostream Msg;
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
@@ -413,8 +412,7 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
}
}
if (Error) {
- std::string msg;
- raw_string_ostream Msg(msg);
+ string_ostream Msg;
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
@@ -471,8 +469,7 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
// Emit the inline asm to a temporary string so we can emit it through
// EmitInlineAsm.
- SmallString<256> StringData;
- raw_svector_ostream OS(StringData);
+ small_string_ostream<256> OS;
// The variant of the current asmprinter.
int AsmPrinterVariant = MAI->getAssemblerDialect();
@@ -517,8 +514,7 @@ void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
}
OS << Counter;
} else {
- std::string msg;
- raw_string_ostream Msg(msg);
+ string_ostream Msg;
Msg << "Unknown special formatter '" << Code
<< "' for machine instr: " << *MI;
report_fatal_error(Msg.str());