diff options
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/Core.cpp | 37 | ||||
-rw-r--r-- | lib/IR/DataLayout.cpp | 3 | ||||
-rw-r--r-- | lib/IR/LLVMContext.cpp | 15 |
3 files changed, 22 insertions, 33 deletions
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 2c49d5b949..bf936d6dc7 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -62,6 +62,11 @@ void LLVMShutdown() { /*===-- Error handling ----------------------------------------------------===*/ +static char *LLVMCreateMessage(StringRef Message) { + assert(Message.find('\0') == Message.npos); + return strndup(Message.data(), Message.size()); +} + char *LLVMCreateMessage(const char *Message) { return strdup(Message); } @@ -110,14 +115,10 @@ unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) { } char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) { - std::string MsgStorage; - raw_string_ostream Stream(MsgStorage); - DiagnosticPrinterRawOStream DP(Stream); - + string_ostream Msg; + DiagnosticPrinterRawOStream DP(Msg); unwrap(DI)->print(DP); - Stream.flush(); - - return LLVMCreateMessage(MsgStorage.c_str()); + return LLVMCreateMessage(Msg.str()); } LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){ @@ -201,13 +202,9 @@ LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, } char *LLVMPrintModuleToString(LLVMModuleRef M) { - std::string buf; - raw_string_ostream os(buf); - + string_ostream os; unwrap(M)->print(os, nullptr); - os.flush(); - - return strdup(buf.c_str()); + return LLVMCreateMessage(os.str()); } /*--.. Operations on inline assembler ......................................--*/ @@ -278,17 +275,14 @@ void LLVMDumpType(LLVMTypeRef Ty) { } char *LLVMPrintTypeToString(LLVMTypeRef Ty) { - std::string buf; - raw_string_ostream os(buf); + string_ostream os; if (unwrap(Ty)) unwrap(Ty)->print(os); else os << "Printing <null> Type"; - os.flush(); - - return strdup(buf.c_str()); + return strndup(os.str().data(), os.str().size()); } /*--.. Operations on integer types .........................................--*/ @@ -532,17 +526,14 @@ void LLVMDumpValue(LLVMValueRef Val) { } char* LLVMPrintValueToString(LLVMValueRef Val) { - std::string buf; - raw_string_ostream os(buf); + string_ostream os; if (unwrap(Val)) unwrap(Val)->print(os); else os << "Printing <null> Value"; - os.flush(); - - return strdup(buf.c_str()); + return strndup(os.str().data(), os.str().size()); } void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) { diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index dea05fbef4..3aa775097d 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -519,8 +519,7 @@ const StructLayout *DataLayout::getStructLayout(StructType *Ty) const { } std::string DataLayout::getStringRepresentation() const { - std::string Result; - raw_string_ostream OS(Result); + string_ostream OS; OS << (LittleEndian ? "e" : "E"); diff --git a/lib/IR/LLVMContext.cpp b/lib/IR/LLVMContext.cpp index de825f00b2..201b278285 100644 --- a/lib/IR/LLVMContext.cpp +++ b/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; } } |