summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/LLVMContext.cpp
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
commit614717388cfccd6a6d34ed17a4680181e22cab22 (patch)
tree98ceaaca266d95b9e657783de3452ee20f891178 /llvm/lib/IR/LLVMContext.cpp
parent49f09fd88afbf04a2c661c1917665b46f96729fa (diff)
downloadbcm5719-llvm-614717388cfccd6a6d34ed17a4680181e22cab22.tar.gz
bcm5719-llvm-614717388cfccd6a6d34ed17a4680181e22cab22.zip
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. llvm-svn: 211749
Diffstat (limited to 'llvm/lib/IR/LLVMContext.cpp')
-rw-r--r--llvm/lib/IR/LLVMContext.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index de825f00b20..201b278285c 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -164,23 +164,22 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) {
}
// Otherwise, print the message with a prefix based on the severity.
- std::string MsgStorage;
- raw_string_ostream Stream(MsgStorage);
- DiagnosticPrinterRawOStream DP(Stream);
+ string_ostream Msg;
+ DiagnosticPrinterRawOStream DP(Msg);
DI.print(DP);
- Stream.flush();
+
switch (DI.getSeverity()) {
case DS_Error:
- errs() << "error: " << MsgStorage << "\n";
+ errs() << "error: " << Msg.str() << "\n";
exit(1);
case DS_Warning:
- errs() << "warning: " << MsgStorage << "\n";
+ errs() << "warning: " << Msg.str() << "\n";
break;
case DS_Remark:
- errs() << "remark: " << MsgStorage << "\n";
+ errs() << "remark: " << Msg.str() << "\n";
break;
case DS_Note:
- errs() << "note: " << MsgStorage << "\n";
+ errs() << "note: " << Msg.str() << "\n";
break;
}
}
OpenPOWER on IntegriCloud