[llvm] r211749 - Introduce a string_ostream string builder facilty

Alp Toker alp at nuanti.com
Wed Jun 25 17:00:49 PDT 2014


Author: alp
Date: Wed Jun 25 19:00:48 2014
New Revision: 211749

URL: http://llvm.org/viewvc/llvm-project?rev=211749&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Analysis/CFGPrinter.h
    llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h
    llvm/trunk/include/llvm/Support/GraphWriter.h
    llvm/trunk/include/llvm/Support/YAMLTraits.h
    llvm/trunk/include/llvm/Support/raw_ostream.h
    llvm/trunk/include/llvm/TableGen/StringToOffsetTable.h
    llvm/trunk/lib/Analysis/Analysis.cpp
    llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
    llvm/trunk/lib/Analysis/Lint.cpp
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
    llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
    llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
    llvm/trunk/lib/CodeGen/MachineFunction.cpp
    llvm/trunk/lib/CodeGen/MachineScheduler.cpp
    llvm/trunk/lib/CodeGen/ScheduleDAGInstrs.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
    llvm/trunk/lib/CodeGen/TargetSchedule.cpp
    llvm/trunk/lib/DebugInfo/DWARFDebugFrame.cpp
    llvm/trunk/lib/IR/Core.cpp
    llvm/trunk/lib/IR/DataLayout.cpp
    llvm/trunk/lib/IR/LLVMContext.cpp
    llvm/trunk/lib/IRReader/IRReader.cpp
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
    llvm/trunk/lib/MC/MCDwarf.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/lib/Object/MachOObjectFile.cpp
    llvm/trunk/lib/Option/Arg.cpp
    llvm/trunk/lib/Support/CommandLine.cpp
    llvm/trunk/lib/Support/raw_ostream.cpp
    llvm/trunk/lib/TableGen/SetTheory.cpp
    llvm/trunk/lib/TableGen/TGParser.cpp
    llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
    llvm/trunk/lib/Target/TargetMachineC.cpp
    llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
    llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
    llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
    llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp
    llvm/trunk/lib/Transforms/Instrumentation/DebugIR.cpp
    llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
    llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
    llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
    llvm/trunk/lib/Transforms/Utils/ASanStackFrameLayout.cpp
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/trunk/tools/llvm-ar/llvm-ar.cpp
    llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
    llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp
    llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp
    llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
    llvm/trunk/utils/FileCheck/FileCheck.cpp
    llvm/trunk/utils/TableGen/CodeEmitterGen.cpp
    llvm/trunk/utils/yaml-bench/YAMLBench.cpp

Modified: llvm/trunk/include/llvm/Analysis/CFGPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CFGPrinter.h?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/CFGPrinter.h (original)
+++ llvm/trunk/include/llvm/Analysis/CFGPrinter.h Wed Jun 25 19:00:48 2014
@@ -36,9 +36,7 @@ struct DOTGraphTraits<const Function*> :
     if (!Node->getName().empty())
       return Node->getName().str();
 
-    std::string Str;
-    raw_string_ostream OS(Str);
-
+    string_ostream OS;
     Node->printAsOperand(OS, false);
     return OS.str();
   }
@@ -46,8 +44,7 @@ struct DOTGraphTraits<const Function*> :
   static std::string getCompleteNodeLabel(const BasicBlock *Node,
                                           const Function *) {
     enum { MaxColumns = 80 };
-    std::string Str;
-    raw_string_ostream OS(Str);
+    string_ostream OS;
 
     if (Node->getName().empty()) {
       Node->printAsOperand(OS, false);
@@ -109,8 +106,7 @@ struct DOTGraphTraits<const Function*> :
 
       if (SuccNo == 0) return "def";
 
-      std::string Str;
-      raw_string_ostream OS(Str);
+      string_ostream OS;
       SwitchInst::ConstCaseIt Case =
           SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
       OS << Case.getCaseValue()->getValue();

Modified: llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h Wed Jun 25 19:00:48 2014
@@ -58,23 +58,18 @@ protected:
 class ObjectBufferStream : public ObjectBuffer {
   void anchor() override;
 public:
-  ObjectBufferStream() : OS(SV) {}
+  ObjectBufferStream() {}
   virtual ~ObjectBufferStream() {}
 
   raw_ostream &getOStream() { return OS; }
   void flush()
   {
-    OS.flush();
-
     // Make the data accessible via the ObjectBuffer::Buffer
-    Buffer.reset(MemoryBuffer::getMemBuffer(StringRef(SV.data(), SV.size()),
-                                            "",
-                                            false));
+    Buffer.reset(MemoryBuffer::getMemBuffer(OS.str(), "", false));
   }
 
 protected:
-  SmallVector<char, 4096> SV; // Working buffer into which we JIT.
-  raw_svector_ostream     OS; // streaming wrapper
+  small_string_ostream<4096> OS; // Working buffer into which we JIT.
 };
 
 } // namespace llvm

Modified: llvm/trunk/include/llvm/Support/GraphWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GraphWriter.h?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GraphWriter.h (original)
+++ llvm/trunk/include/llvm/Support/GraphWriter.h Wed Jun 25 19:00:48 2014
@@ -184,8 +184,7 @@ public:
         O << "|" << DOT::EscapeString(NodeDesc);
     }
 
-    std::string edgeSourceLabels;
-    raw_string_ostream EdgeSourceLabels(edgeSourceLabels);
+    string_ostream EdgeSourceLabels;
     bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
 
     if (hasEdgeSourceLabels) {

Modified: llvm/trunk/include/llvm/Support/YAMLTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/YAMLTraits.h (original)
+++ llvm/trunk/include/llvm/Support/YAMLTraits.h Wed Jun 25 19:00:48 2014
@@ -612,8 +612,7 @@ template<typename T>
 typename std::enable_if<has_ScalarTraits<T>::value,void>::type
 yamlize(IO &io, T &Val, bool) {
   if ( io.outputting() ) {
-    std::string Storage;
-    llvm::raw_string_ostream Buffer(Storage);
+    llvm::string_ostream Buffer;
     ScalarTraits<T>::output(Val, io.getContext(), Buffer);
     StringRef Str = Buffer.str();
     io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Wed Jun 25 19:00:48 2014
@@ -15,6 +15,7 @@
 #define LLVM_SUPPORT_RAW_OSTREAM_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataTypes.h"
 
@@ -461,6 +462,14 @@ class raw_svector_ostream : public raw_o
   /// current_pos - Return the current position within the stream, not
   /// counting the bytes currently in the buffer.
   uint64_t current_pos() const override;
+
+protected:
+  // This constructor is specified not to access \p O provided for storage as it
+  // may not yet be initialized at construction time.
+  explicit raw_svector_ostream(SmallVectorImpl<char> &O, std::nullptr_t)
+      : OS(O){};
+  void init();
+
 public:
   /// Construct a new raw_svector_ostream.
   ///
@@ -493,6 +502,25 @@ public:
   ~raw_null_ostream();
 };
 
+/// string_ostream - A raw_ostream that builds a string.  This is a
+/// raw_svector_ostream with storage.
+template <unsigned InternalLen>
+class small_string_ostream : public raw_svector_ostream {
+  SmallVector<char, InternalLen> Buffer;
+  // There's no need to flush explicitly.
+  using raw_svector_ostream::flush;
+
+public:
+  small_string_ostream() : raw_svector_ostream(Buffer, nullptr) { init(); }
+
+  void clear() {
+    flush();
+    Buffer.clear();
+  }
+};
+
+typedef small_string_ostream<128> string_ostream;
+
 } // end llvm namespace
 
 #endif

Modified: llvm/trunk/include/llvm/TableGen/StringToOffsetTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/StringToOffsetTable.h?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/StringToOffsetTable.h (original)
+++ llvm/trunk/include/llvm/TableGen/StringToOffsetTable.h Wed Jun 25 19:00:48 2014
@@ -42,8 +42,8 @@ public:
 
   void EmitString(raw_ostream &O) {
     // Escape the string.
-    SmallString<256> Str;
-    raw_svector_ostream(Str).write_escaped(AggregateString);
+    small_string_ostream<256> Str;
+    Str.write_escaped(AggregateString);
     AggregateString = Str.str();
 
     O << "    \"";

Modified: llvm/trunk/lib/Analysis/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Analysis.cpp (original)
+++ llvm/trunk/lib/Analysis/Analysis.cpp Wed Jun 25 19:00:48 2014
@@ -75,8 +75,7 @@ void LLVMInitializeAnalysis(LLVMPassRegi
 LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
                           char **OutMessages) {
   raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
-  std::string Messages;
-  raw_string_ostream MsgsOS(Messages);
+  string_ostream MsgsOS;
 
   LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
 
@@ -88,7 +87,7 @@ LLVMBool LLVMVerifyModule(LLVMModuleRef
     report_fatal_error("Broken module found, compilation aborted!");
 
   if (OutMessages)
-    *OutMessages = strdup(MsgsOS.str().c_str());
+    *OutMessages = strndup(MsgsOS.str().data(), MsgsOS.str().size());
 
   return Result;
 }

Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp Wed Jun 25 19:00:48 2014
@@ -82,10 +82,9 @@ struct DOTGraphTraits<BlockFrequencyInfo
 
   std::string getNodeLabel(const BasicBlock *Node,
                            const BlockFrequencyInfo *Graph) {
-    std::string Result;
-    raw_string_ostream OS(Result);
+    string_ostream OS;
 
-    OS << Node->getName().str() << ":";
+    OS << Node->getName() << ":";
     switch (ViewBlockFreqPropagationDAG) {
     case GVDT_Fraction:
       Graph->printBlockFreq(OS, Node);
@@ -98,7 +97,7 @@ struct DOTGraphTraits<BlockFrequencyInfo
                        "never reach this point.");
     }
 
-    return Result;
+    return OS.str();
   }
 };
 

Modified: llvm/trunk/lib/Analysis/Lint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Lint.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Lint.cpp (original)
+++ llvm/trunk/lib/Analysis/Lint.cpp Wed Jun 25 19:00:48 2014
@@ -105,11 +105,10 @@ namespace {
     const DataLayout *DL;
     TargetLibraryInfo *TLI;
 
-    std::string Messages;
-    raw_string_ostream MessagesStr;
+    string_ostream MessagesStr;
 
     static char ID; // Pass identification, replacement for typeid
-    Lint() : FunctionPass(ID), MessagesStr(Messages) {
+    Lint() : FunctionPass(ID) {
       initializeLintPass(*PassRegistry::getPassRegistry());
     }
 
@@ -181,7 +180,7 @@ bool Lint::runOnFunction(Function &F) {
   TLI = &getAnalysis<TargetLibraryInfo>();
   visit(F);
   dbgs() << MessagesStr.str();
-  Messages.clear();
+  MessagesStr.clear();
   return false;
 }
 

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Jun 25 19:00:48 2014
@@ -28,10 +28,9 @@
 using namespace llvm;
 
 static std::string getTypeString(Type *T) {
-  std::string Result;
-  raw_string_ostream Tmp(Result);
-  Tmp << *T;
-  return Tmp.str();
+  string_ostream Result;
+  Result << *T;
+  return Result.str();
 }
 
 /// Run: module ::= toplevelentity*

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Jun 25 19:00:48 2014
@@ -1585,8 +1585,7 @@ static const MCExpr *lowerConstant(const
 
     // 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());

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Wed Jun 25 19:00:48 2014
@@ -241,8 +241,7 @@ static void EmitMSInlineAsmStr(const cha
         }
       }
       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 ch
           }
         }
         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 Mac
 
   // 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 Mach
     }
     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());

Modified: llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp Wed Jun 25 19:00:48 2014
@@ -89,10 +89,9 @@ struct DOTGraphTraits<MachineBlockFreque
 
   std::string getNodeLabel(const MachineBasicBlock *Node,
                            const MachineBlockFrequencyInfo *Graph) {
-    std::string Result;
-    raw_string_ostream OS(Result);
+    string_ostream OS;
 
-    OS << Node->getName().str() << ":";
+    OS << Node->getName() << ":";
     switch (ViewMachineBlockFreqPropagationDAG) {
     case GVDT_Fraction:
       Graph->printBlockFreq(OS, Node);
@@ -105,7 +104,7 @@ struct DOTGraphTraits<MachineBlockFreque
                        "never reach this point.");
     }
 
-    return Result;
+    return OS.str();
   }
 };
 

Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Wed Jun 25 19:00:48 2014
@@ -264,23 +264,19 @@ INITIALIZE_PASS_END(MachineBlockPlacemen
 ///
 /// Only used by debug logging.
 static std::string getBlockName(MachineBasicBlock *BB) {
-  std::string Result;
-  raw_string_ostream OS(Result);
+  string_ostream OS;
   OS << "BB#" << BB->getNumber()
      << " (derived from LLVM BB '" << BB->getName() << "')";
-  OS.flush();
-  return Result;
+  return OS.str();
 }
 
 /// \brief Helper to print the number of a MBB.
 ///
 /// Only used by debug logging.
 static std::string getBlockNum(MachineBasicBlock *BB) {
-  std::string Result;
-  raw_string_ostream OS(Result);
+  string_ostream OS;
   OS << "BB#" << BB->getNumber();
-  OS.flush();
-  return Result;
+  return OS.str();
 }
 #endif
 

Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Wed Jun 25 19:00:48 2014
@@ -465,9 +465,8 @@ MCSymbol *MachineFunction::getJTISymbol(
 
   const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
                                          DL->getPrivateGlobalPrefix();
-  SmallString<60> Name;
-  raw_svector_ostream(Name)
-    << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
+  small_string_ostream<60> Name;
+  Name << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
   return Ctx.GetOrCreateSymbol(Name.str());
 }
 

Modified: llvm/trunk/lib/CodeGen/MachineScheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineScheduler.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineScheduler.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineScheduler.cpp Wed Jun 25 19:00:48 2014
@@ -3235,8 +3235,7 @@ struct DOTGraphTraits<ScheduleDAGMI*> :
   }
 
   static std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *G) {
-    std::string Str;
-    raw_string_ostream SS(Str);
+    string_ostream SS;
     const ScheduleDAGMI *DAG = static_cast<const ScheduleDAGMI*>(G);
     const SchedDFSResult *DFS = DAG->hasVRegLiveness() ?
       static_cast<const ScheduleDAGMILive*>(G)->getDFSResult() : nullptr;

Modified: llvm/trunk/lib/CodeGen/ScheduleDAGInstrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ScheduleDAGInstrs.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ScheduleDAGInstrs.cpp (original)
+++ llvm/trunk/lib/CodeGen/ScheduleDAGInstrs.cpp Wed Jun 25 19:00:48 2014
@@ -1197,8 +1197,7 @@ void ScheduleDAGInstrs::dumpNode(const S
 }
 
 std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
-  std::string s;
-  raw_string_ostream oss(s);
+  string_ostream oss;
   if (SU == &EntrySU)
     oss << "<entry>";
   else if (SU == &ExitSU)

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Wed Jun 25 19:00:48 2014
@@ -3245,8 +3245,7 @@ SelectCodeCommon(SDNode *NodeToMatch, co
 
 
 void SelectionDAGISel::CannotYetSelect(SDNode *N) {
-  std::string msg;
-  raw_string_ostream Msg(msg);
+  string_ostream Msg;
   Msg << "Cannot select: ";
 
   if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp Wed Jun 25 19:00:48 2014
@@ -268,8 +268,7 @@ void SelectionDAG::setSubgraphColor(SDNo
 }
 
 std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
-  std::string s;
-  raw_string_ostream O(s);
+  string_ostream O;
   O << "SU(" << SU->NodeNum << "): ";
   if (SU->getNode()) {
     SmallVector<SDNode *, 4> GluedNodes;

Modified: llvm/trunk/lib/CodeGen/TargetSchedule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetSchedule.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetSchedule.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetSchedule.cpp Wed Jun 25 19:00:48 2014
@@ -212,11 +212,10 @@ unsigned TargetSchedModel::computeOperan
   if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit()
       && !DefMI->getDesc().OpInfo[DefOperIdx].isOptionalDef()
       && SchedModel.isComplete()) {
-    std::string Err;
-    raw_string_ostream ss(Err);
-    ss << "DefIdx " << DefIdx << " exceeds machine model writes for "
-       << *DefMI;
-    report_fatal_error(ss.str());
+    string_ostream Err;
+    Err << "DefIdx " << DefIdx << " exceeds machine model writes for "
+        << *DefMI;
+    report_fatal_error(Err.str());
   }
 #endif
   // FIXME: Automatically giving all implicit defs defaultDefLatency is

Modified: llvm/trunk/lib/DebugInfo/DWARFDebugFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugFrame.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFDebugFrame.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFDebugFrame.cpp Wed Jun 25 19:00:48 2014
@@ -353,10 +353,9 @@ void DWARFDebugFrame::parse(DataExtracto
     Entries.back()->parseInstructions(Data, &Offset, EndStructureOffset);
 
     if (Offset != EndStructureOffset) {
-      std::string Str;
-      raw_string_ostream OS(Str);
-      OS << format("Parsing entry instructions at %lx failed", StartOffset);
-      report_fatal_error(Str);
+      string_ostream Str;
+      Str << format("Parsing entry instructions at %lx failed", StartOffset);
+      report_fatal_error(Str.str());
     }
   }
 }

Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Wed Jun 25 19:00:48 2014
@@ -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* Nam
 }
 
 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(LLVMModul
 }
 
 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) {

Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Wed Jun 25 19:00:48 2014
@@ -519,8 +519,7 @@ const StructLayout *DataLayout::getStruc
 }
 
 std::string DataLayout::getStringRepresentation() const {
-  std::string Result;
-  raw_string_ostream OS(Result);
+  string_ostream OS;
 
   OS << (LittleEndian ? "e" : "E");
 

Modified: llvm/trunk/lib/IR/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContext.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContext.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContext.cpp Wed Jun 25 19:00:48 2014
@@ -164,23 +164,22 @@ void LLVMContext::diagnose(const Diagnos
   }
 
   // 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;
   }
 }

Modified: llvm/trunk/lib/IRReader/IRReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IRReader/IRReader.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/IRReader/IRReader.cpp (original)
+++ llvm/trunk/lib/IRReader/IRReader.cpp Wed Jun 25 19:00:48 2014
@@ -108,13 +108,9 @@ LLVMBool LLVMParseIRInContext(LLVMContex
 
   if(!*OutM) {
     if (OutMessage) {
-      std::string buf;
-      raw_string_ostream os(buf);
-
+      string_ostream os;
       Diag.print(nullptr, os, false);
-      os.flush();
-
-      *OutMessage = strdup(buf.c_str());
+      *OutMessage = strndup(os.str().data(), os.str().size());
     }
     return 1;
   }

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Wed Jun 25 19:00:48 2014
@@ -549,16 +549,17 @@ void LTOCodeGenerator::DiagnosticHandler
     break;
   }
   // Create the string that will be reported to the external diagnostic handler.
-  std::string MsgStorage;
-  raw_string_ostream Stream(MsgStorage);
-  DiagnosticPrinterRawOStream DP(Stream);
+  string_ostream Msg;
+  DiagnosticPrinterRawOStream DP(Msg);
   DI.print(DP);
-  Stream.flush();
+
+  // Null-terminate the C string.
+  Msg << '\0';
 
   // If this method has been called it means someone has set up an external
   // diagnostic handler. Assert on that.
   assert(DiagHandler && "Invalid diagnostic handler");
-  (*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext);
+  (*DiagHandler)(Severity, Msg.str().data(), DiagContext);
 }
 
 void

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Wed Jun 25 19:00:48 2014
@@ -1175,9 +1175,10 @@ void MCAsmStreamer::AddEncodingComment(c
   raw_ostream &OS = GetCommentOS();
   SmallString<256> Code;
   SmallVector<MCFixup, 4> Fixups;
-  raw_svector_ostream VecOS(Code);
-  Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
-  VecOS.flush();
+  {
+    raw_svector_ostream VecOS(Code);
+    Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
+  }
 
   // If we are showing fixups, create symbolic markers in the encoded
   // representation. We do this by making a per-bit map to the fixup item index,

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Wed Jun 25 19:00:48 2014
@@ -140,17 +140,15 @@ MCSymbol *MCContext::GetOrCreateSymbol(c
 }
 
 MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
-  SmallString<128> NameSV;
-  raw_svector_ostream(NameSV)
-    << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
-  return CreateSymbol(NameSV);
+  small_string_ostream<128> NameSV;
+  NameSV << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
+  return CreateSymbol(NameSV.str());
 }
 
 MCSymbol *MCContext::CreateTempSymbol() {
-  SmallString<128> NameSV;
-  raw_svector_ostream(NameSV)
-    << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
-  return CreateSymbol(NameSV);
+  small_string_ostream<128> NameSV;
+  NameSV << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
+  return CreateSymbol(NameSV.str());
 }
 
 unsigned MCContext::NextInstance(unsigned LocalLabelVal) {

Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp (original)
+++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp Wed Jun 25 19:00:48 2014
@@ -270,8 +270,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmC
   const MCDisassembler *DisAsm = DC->getDisAsm();
   MCInstPrinter *IP = DC->getIP();
   MCDisassembler::DecodeStatus S;
-  SmallVector<char, 64> InsnStr;
-  raw_svector_ostream Annotations(InsnStr);
+  small_string_ostream<64> Annotations;
   S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC,
                              /*REMOVE*/ nulls(), Annotations);
   switch (S) {
@@ -281,13 +280,10 @@ size_t LLVMDisasmInstruction(LLVMDisasmC
     return 0;
 
   case MCDisassembler::Success: {
-    Annotations.flush();
-    StringRef AnnotationsStr = Annotations.str();
-
     SmallVector<char, 64> InsnStr;
     raw_svector_ostream OS(InsnStr);
     formatted_raw_ostream FormattedOS(OS);
-    IP->printInst(&Inst, FormattedOS, AnnotationsStr);
+    IP->printInst(&Inst, FormattedOS, Annotations.str());
 
     if (DC->getOptions() & LLVMDisassembler_Option_PrintLatency)
       emitLatency(DC, Inst);

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Wed Jun 25 19:00:48 2014
@@ -420,8 +420,7 @@ unsigned MCDwarfLineTableHeader::getFile
 void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
                            uint64_t AddrDelta) {
   MCContext &Context = MCOS->getContext();
-  SmallString<256> Tmp;
-  raw_svector_ostream OS(Tmp);
+  small_string_ostream<256> OS;
   MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
   MCOS->EmitBytes(OS.str());
 }
@@ -1647,8 +1646,7 @@ void MCDwarfFrameEmitter::Emit(MCObjectS
 void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
                                          uint64_t AddrDelta) {
   MCContext &Context = Streamer.getContext();
-  SmallString<256> Tmp;
-  raw_svector_ostream OS(Tmp);
+  small_string_ostream<256> OS;
   MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
   Streamer.EmitBytes(OS.str());
 }

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Jun 25 19:00:48 2014
@@ -4580,8 +4580,7 @@ bool AsmParser::parseMSInlineAsm(
   }
 
   // Build the IR assembly string.
-  std::string AsmStringIR;
-  raw_string_ostream OS(AsmStringIR);
+  string_ostream OS;
   const char *AsmStart = SrcMgr.getMemoryBuffer(0)->getBufferStart();
   const char *AsmEnd = SrcMgr.getMemoryBuffer(0)->getBufferEnd();
   array_pod_sort(AsmStrRewrites.begin(), AsmStrRewrites.end(), rewritesSort);
@@ -4646,8 +4645,7 @@ bool AsmParser::parseMSInlineAsm(
     }
     case AOK_DotOperator:
       // Insert the dot if the user omitted it.
-      OS.flush();
-      if (AsmStringIR.back() != '.')
+      if (OS.str().back() != '.')
         OS << '.';
       OS << AR.Val;
       break;

Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Wed Jun 25 19:00:48 2014
@@ -301,7 +301,7 @@ static unsigned getCPUType(const MachOOb
 
 static void printRelocationTargetName(const MachOObjectFile *O,
                                       const MachO::any_relocation_info &RE,
-                                      raw_string_ostream &fmt) {
+                                      raw_ostream &fmt) {
   bool IsScattered = O->isRelocationScattered(RE);
 
   // Target of a scattered relocation is an address.  In the interest of
@@ -1010,8 +1010,7 @@ MachOObjectFile::getRelocationValueStrin
 
   unsigned Arch = this->getArch();
 
-  std::string fmtbuf;
-  raw_string_ostream fmt(fmtbuf);
+  string_ostream fmt;
   unsigned Type = this->getAnyRelocationType(RE);
   bool IsPCRel = this->getAnyRelocationPCRel(RE);
 
@@ -1174,7 +1173,7 @@ MachOObjectFile::getRelocationValueStrin
   } else
     printRelocationTargetName(this, RE, fmt);
 
-  fmt.flush();
+  StringRef fmtbuf = fmt.str();
   Result.append(fmtbuf.begin(), fmtbuf.end());
   return object_error::success;
 }

Modified: llvm/trunk/lib/Option/Arg.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Option/Arg.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Option/Arg.cpp (original)
+++ llvm/trunk/lib/Option/Arg.cpp Wed Jun 25 19:00:48 2014
@@ -62,8 +62,7 @@ void Arg::dump() const {
 }
 
 std::string Arg::getAsString(const ArgList &Args) const {
-  SmallString<256> Res;
-  llvm::raw_svector_ostream OS(Res);
+  small_string_ostream<256> OS;
 
   ArgStringList ASL;
   render(Args, ASL);
@@ -95,8 +94,7 @@ void Arg::render(const ArgList &Args, Ar
     break;
 
   case Option::RenderCommaJoinedStyle: {
-    SmallString<256> Res;
-    llvm::raw_svector_ostream OS(Res);
+    small_string_ostream<256> OS;
     OS << getSpelling();
     for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
       if (i) OS << ',';

Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Wed Jun 25 19:00:48 2014
@@ -1342,25 +1342,21 @@ printGenericOptionDiff(const Option &O,
 
 // printOptionDiff - Specializations for printing basic value types.
 //
-#define PRINT_OPT_DIFF(T)                                               \
-  void parser<T>::                                                      \
-  printOptionDiff(const Option &O, T V, OptionValue<T> D,               \
-                  size_t GlobalWidth) const {                           \
-    printOptionName(O, GlobalWidth);                                    \
-    std::string Str;                                                    \
-    {                                                                   \
-      raw_string_ostream SS(Str);                                       \
-      SS << V;                                                          \
-    }                                                                   \
-    outs() << "= " << Str;                                              \
-    size_t NumSpaces = MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0;\
-    outs().indent(NumSpaces) << " (default: ";                          \
-    if (D.hasValue())                                                   \
-      outs() << D.getValue();                                           \
-    else                                                                \
-      outs() << "*no default*";                                         \
-    outs() << ")\n";                                                    \
-  }                                                                     \
+#define PRINT_OPT_DIFF(T)                                                      \
+  void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D,      \
+                                  size_t GlobalWidth) const {                  \
+    printOptionName(O, GlobalWidth);                                           \
+    string_ostream SS;                                                         \
+    SS << V;                                                                   \
+    outs() << "= " << SS.str();                                                \
+    size_t NumSpaces = MaxOptWidth > SS.tell() ? MaxOptWidth - SS.tell() : 0;  \
+    outs().indent(NumSpaces) << " (default: ";                                 \
+    if (D.hasValue())                                                          \
+      outs() << D.getValue();                                                  \
+    else                                                                       \
+      outs() << "*no default*";                                                \
+    outs() << ")\n";                                                           \
+  }
 
 PRINT_OPT_DIFF(bool)
 PRINT_OPT_DIFF(boolOrDefault)

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Wed Jun 25 19:00:48 2014
@@ -704,6 +704,10 @@ void raw_string_ostream::write_impl(cons
 // and we only need to set the vector size when the data is flushed.
 
 raw_svector_ostream::raw_svector_ostream(SmallVectorImpl<char> &O) : OS(O) {
+  init();
+}
+
+void raw_svector_ostream::init() {
   // Set up the initial external buffer. We make sure that the buffer has at
   // least 128 bytes free; raw_ostream itself only requires 64, but we want to
   // make sure that we don't grow the buffer unnecessarily on destruction (when

Modified: llvm/trunk/lib/TableGen/SetTheory.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/SetTheory.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/SetTheory.cpp (original)
+++ llvm/trunk/lib/TableGen/SetTheory.cpp Wed Jun 25 19:00:48 2014
@@ -209,13 +209,12 @@ struct SequenceOp : public SetTheory::Op
         break;
       else if (Step < 0 && From < To)
         break;
-      std::string Name;
-      raw_string_ostream OS(Name);
-      OS << format(Format.c_str(), unsigned(From));
-      Record *Rec = Records.getDef(OS.str());
+      string_ostream Name;
+      Name << format(Format.c_str(), unsigned(From));
+      Record *Rec = Records.getDef(Name.str());
       if (!Rec)
-        PrintFatalError(Loc, "No def named '" + Name + "': " +
-          Expr->getAsString());
+        PrintFatalError(Loc, "No def named '" + Name.str() + "': " +
+                                 Expr->getAsString());
       // Try to reevaluate Rec in case it is a set.
       if (const RecVec *Result = ST.expand(Rec))
         Elts.insert(Result->begin(), Result->end());

Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Wed Jun 25 19:00:48 2014
@@ -1307,8 +1307,7 @@ Init *TGParser::ParseSimpleValue(Record
     if (ItemType) {
       ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
       if (!ListType) {
-        std::string s;
-        raw_string_ostream ss(s);
+        string_ostream ss;
         ss << "Type mismatch for list, expected list type, got "
            << ItemType->getAsString();
         TokError(ss.str());

Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Wed Jun 25 19:00:48 2014
@@ -146,8 +146,7 @@ const MCExpr *nvptx::LowerConstant(const
 
     // 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());

Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Wed Jun 25 19:00:48 2014
@@ -237,15 +237,13 @@ LLVMBool LLVMTargetMachineEmitToFile(LLV
 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
   LLVMModuleRef M, LLVMCodeGenFileType codegen, char** ErrorMessage,
   LLVMMemoryBufferRef *OutMemBuf) {
-  std::string CodeString;
-  raw_string_ostream OStream(CodeString);
-  formatted_raw_ostream Out(OStream);
+  string_ostream Code;
+  formatted_raw_ostream Out(Code);
   bool Result = LLVMTargetMachineEmit(T, M, Out, codegen, ErrorMessage);
-  OStream.flush();
 
-  std::string &Data = OStream.str();
-  *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Data.c_str(),
-                                                     Data.length(), "");
+  StringRef Buffer = Code.str();
+  *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Buffer.data(),
+                                                         Buffer.size(), "");
   return Result;
 }
 

Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Wed Jun 25 19:00:48 2014
@@ -2412,8 +2412,7 @@ bool X86AsmParser::MatchAndEmitInstructi
     if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
     if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
 
-    SmallString<126> Msg;
-    raw_svector_ostream OS(Msg);
+    small_string_ostream<128> OS;
     OS << "ambiguous instructions require an explicit suffix (could be ";
     for (unsigned i = 0; i != NumMatches; ++i) {
       if (i != 0)

Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp Wed Jun 25 19:00:48 2014
@@ -281,8 +281,7 @@ void X86AsmBackend::relaxInstruction(con
   unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
 
   if (RelaxedOp == Inst.getOpcode()) {
-    SmallString<256> Tmp;
-    raw_svector_ostream OS(Tmp);
+    small_string_ostream<256> OS;
     Inst.dump_pretty(OS);
     OS << "\n";
     report_fatal_error("unexpected instruction to relax: " + OS.str());

Modified: llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp Wed Jun 25 19:00:48 2014
@@ -550,8 +550,7 @@ emitNonLazySymbolPointer(MCStreamer &Out
 }
 
 void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
-  SmallString<128> Directive;
-  raw_svector_ostream OS(Directive);
+  small_string_ostream<128> OS;
   StringRef Name = Sym->getName();
 
   if (Subtarget->isTargetKnownWindowsMSVC())
@@ -572,8 +571,7 @@ void X86AsmPrinter::GenerateExportDirect
       OS << ",data";
   }
 
-  OS.flush();
-  OutStreamer.EmitBytes(Directive);
+  OutStreamer.EmitBytes(OS.str());
 }
 
 void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {

Modified: llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp Wed Jun 25 19:00:48 2014
@@ -267,8 +267,7 @@ PrintAsmMemoryOperand(const MachineInstr
 }
 
 void XCoreAsmPrinter::EmitInstruction(const MachineInstr *MI) {
-  SmallString<128> Str;
-  raw_svector_ostream O(Str);
+  small_string_ostream<128> O;
 
   switch (MI->getOpcode()) {
   case XCore::DBG_VALUE:

Modified: llvm/trunk/lib/Transforms/Instrumentation/DebugIR.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/DebugIR.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/DebugIR.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/DebugIR.cpp Wed Jun 25 19:00:48 2014
@@ -352,14 +352,12 @@ private:
   }
 
   std::string getTypeName(Type *T) {
-    std::string TypeName;
-    raw_string_ostream TypeStream(TypeName);
+    string_ostream OS;
     if (T)
-      T->print(TypeStream);
+      T->print(OS);
     else
-      TypeStream << "Printing <null> Type";
-    TypeStream.flush();
-    return TypeName;
+      OS << "Printing <null> Type";
+    return OS.str();
   }
 
   /// Returns the MDNode that represents type T if it is already created, or 0

Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Wed Jun 25 19:00:48 2014
@@ -316,11 +316,9 @@ namespace {
       }
       ReturnBlock = new GCOVBlock(i++, os);
 
-      std::string FunctionNameAndLine;
-      raw_string_ostream FNLOS(FunctionNameAndLine);
-      FNLOS << getFunctionName(SP) << SP.getLineNumber();
-      FNLOS.flush();
-      FuncChecksum = hash_value(FunctionNameAndLine);
+      string_ostream FnNameLine;
+      FnNameLine << getFunctionName(SP) << SP.getLineNumber();
+      FuncChecksum = hash_value(FnNameLine.str());
     }
 
     ~GCOVFunction() {
@@ -337,15 +335,14 @@ namespace {
     }
 
     std::string getEdgeDestinations() {
-      std::string EdgeDestinations;
-      raw_string_ostream EDOS(EdgeDestinations);
+      string_ostream EdgeDestinations;
       Function *F = Blocks.begin()->first->getParent();
       for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
         GCOVBlock &Block = *Blocks[I];
         for (int i = 0, e = Block.OutEdges.size(); i != e; ++i)
-          EDOS << Block.OutEdges[i]->Number;
+          EdgeDestinations << Block.OutEdges[i]->Number;
       }
-      return EdgeDestinations;
+      return EdgeDestinations.str();
     }
 
     uint32_t getFuncChecksum() {

Modified: llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp Wed Jun 25 19:00:48 2014
@@ -2424,8 +2424,7 @@ struct MemorySanitizerVisitor : public I
 
     if (PoisonStack && MS.TrackOrigins) {
       setOrigin(&I, getCleanOrigin());
-      SmallString<2048> StackDescriptionStorage;
-      raw_svector_ostream StackDescription(StackDescriptionStorage);
+      small_string_ostream<2048> StackDescription;
       // We create a string with a description of the stack allocation and
       // pass it into __msan_set_alloca_origin.
       // It will be printed by the run-time if stack-originated UMR is found.

Modified: llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp Wed Jun 25 19:00:48 2014
@@ -835,8 +835,7 @@ static MDString *AppendMDNodeToSourcePtr
       // of line at the module level and to provide a very simple format
       // encoding the information herein. Both of these makes it simpler to
       // parse the annotations by a simple external program.
-      std::string Str;
-      raw_string_ostream os(Str);
+      string_ostream os;
       os << "(" << Inst->getParent()->getParent()->getName() << ",%"
          << Inst->getName() << ")";
 
@@ -849,8 +848,7 @@ static MDString *AppendMDNodeToSourcePtr
       Hash = cast<MDString>(Node->getOperand(0));
     }
   } else if (Argument *Arg = dyn_cast<Argument>(Ptr)) {
-    std::string str;
-    raw_string_ostream os(str);
+    string_ostream os;
     os << "(" << Arg->getParent()->getName() << ",%" << Arg->getName()
        << ")";
     Hash = MDString::get(Arg->getContext(), os.str());
@@ -860,8 +858,7 @@ static MDString *AppendMDNodeToSourcePtr
 }
 
 static std::string SequenceToString(Sequence A) {
-  std::string str;
-  raw_string_ostream os(str);
+  string_ostream os;
   os << A;
   return os.str();
 }

Modified: llvm/trunk/lib/Transforms/Utils/ASanStackFrameLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ASanStackFrameLayout.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ASanStackFrameLayout.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ASanStackFrameLayout.cpp Wed Jun 25 19:00:48 2014
@@ -65,8 +65,7 @@ ComputeASanStackFrameLayout(SmallVectorI
     Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
 
   std::stable_sort(Vars.begin(), Vars.end(), CompareVars);
-  SmallString<2048> StackDescriptionStorage;
-  raw_svector_ostream StackDescription(StackDescriptionStorage);
+  small_string_ostream<2048> StackDescription;
   StackDescription << NumVars;
   Layout->FrameAlignment = std::max(Granularity, Vars[0].Alignment);
   SmallVector<uint8_t, 64> &SB(Layout->ShadowBytes);

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Wed Jun 25 19:00:48 2014
@@ -212,24 +212,23 @@ class LoopVectorizationCostModel;
 /// Optimization analysis message produced during vectorization. Messages inform
 /// the user why vectorization did not occur.
 class Report {
-  std::string Message;
-  raw_string_ostream Out;
+  string_ostream Message;
   Instruction *Instr;
 
 public:
-  Report(Instruction *I = nullptr) : Out(Message), Instr(I) {
-    Out << "loop not vectorized: ";
+  Report(Instruction *I = nullptr) : Instr(I) {
+    Message << "loop not vectorized: ";
   }
 
   template <typename A> Report &operator<<(const A &Value) {
-    Out << Value;
+    Message << Value;
     return *this;
   }
 
   Instruction *getInstr() { return Instr; }
 
-  std::string &str() { return Out.str(); }
-  operator Twine() { return Out.str(); }
+  StringRef str() { return Message.str(); }
+  operator Twine() { return Message.str(); }
 };
 
 /// InnerLoopVectorizer vectorizes loops which contain only one basic
@@ -503,18 +502,17 @@ static void setDebugLocFromInst(IRBuilde
 #ifndef NDEBUG
 /// \return string containing a file name and a line # for the given loop.
 static std::string getDebugLocString(const Loop *L) {
-  std::string Result;
-  if (L) {
-    raw_string_ostream OS(Result);
-    const DebugLoc LoopDbgLoc = L->getStartLoc();
-    if (!LoopDbgLoc.isUnknown())
-      LoopDbgLoc.print(L->getHeader()->getContext(), OS);
-    else
-      // Just print the module name.
-      OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
-    OS.flush();
-  }
-  return Result;
+  if (!L)
+    return std::string();
+
+  string_ostream OS;
+  const DebugLoc LoopDbgLoc = L->getStartLoc();
+  if (!LoopDbgLoc.isUnknown())
+    LoopDbgLoc.print(L->getHeader()->getContext(), OS);
+  else
+    // Just print the module name.
+    OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
+  return OS.str();
 }
 #endif
 

Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Jun 25 19:00:48 2014
@@ -689,8 +689,7 @@ writeSymbolTable(raw_fd_ostream &Out, Ar
                  std::vector<std::pair<unsigned, unsigned>> &MemberOffsetRefs) {
   unsigned StartOffset = 0;
   unsigned MemberNum = 0;
-  std::string NameBuf;
-  raw_string_ostream NameOS(NameBuf);
+  string_ostream NameOS;
   unsigned NumSyms = 0;
   LLVMContext &Context = getGlobalContext();
   for (ArrayRef<NewArchiveIterator>::iterator I = Members.begin(),

Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Jun 25 19:00:48 2014
@@ -222,8 +222,7 @@ static void emitDOTFile(const char *File
         Out << "<o>";
 
       // Escape special chars and print the instruction in mnemonic form.
-      std::string Str;
-      raw_string_ostream OS(Str);
+      string_ostream OS;
       IP->printInst(&(*i)->getInsts()->at(ii).Inst, OS, "");
       Out << DOT::EscapeString(OS.str());
     }
@@ -473,9 +472,7 @@ static void DisassembleObject(const Obje
     if (Symbols.empty())
       Symbols.push_back(std::make_pair(0, name));
 
-
-    SmallString<40> Comments;
-    raw_svector_ostream CommentStream(Comments);
+    small_string_ostream<40> Comments;
 
     StringRef Bytes;
     if (error(Section.getContents(Bytes)))
@@ -513,15 +510,14 @@ static void DisassembleObject(const Obje
         MCInst Inst;
 
         if (DisAsm->getInstruction(Inst, Size, memoryObject,
-                                   SectionAddr + Index,
-                                   DebugOut, CommentStream)) {
+                                   SectionAddr + Index, DebugOut, Comments)) {
           outs() << format("%8" PRIx64 ":", SectionAddr + Index);
           if (!NoShowRawInsn) {
             outs() << "\t";
             DumpBytes(StringRef(Bytes.data() + Index, Size));
           }
           IP->printInst(&Inst, outs(), "");
-          outs() << CommentStream.str();
+          outs() << Comments.str();
           Comments.clear();
           outs() << "\n";
         } else {

Modified: llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp Wed Jun 25 19:00:48 2014
@@ -95,8 +95,7 @@ raw_ostream &operator<<(raw_ostream &OS,
 
 static std::string formatSymbol(StringRef Name, uint64_t Address,
                                 uint64_t Offset = 0) {
-  std::string Buffer;
-  raw_string_ostream OS(Buffer);
+  string_ostream OS;
 
   if (!Name.empty())
     OS << Name << " ";

Modified: llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/Win64EHDumper.cpp Wed Jun 25 19:00:48 2014
@@ -115,8 +115,7 @@ static unsigned getNumUsedSlots(const Un
 static std::string formatSymbol(const Dumper::Context &Ctx,
                                 const coff_section *Section, uint64_t Offset,
                                 uint32_t Displacement) {
-  std::string Buffer;
-  raw_string_ostream OS(Buffer);
+  string_ostream OS;
 
   StringRef Name;
   SymbolRef Symbol;
@@ -131,6 +130,7 @@ static std::string formatSymbol(const Du
     OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
   else
     OS << format(" (0x%" PRIX64 ")", Offset);
+
   return OS.str();
 }
 

Modified: llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp Wed Jun 25 19:00:48 2014
@@ -70,9 +70,9 @@ Function *makeReturnGlobal(std::string N
 }
 
 std::string DumpFunction(const Function *F) {
-  std::string Result;
-  raw_string_ostream(Result) << "" << *F;
-  return Result;
+  string_ostream Result;
+  Result << "" << *F;
+  return Result.str();
 }
 
 class RecordingJITMemoryManager : public JITMemoryManager {
@@ -170,10 +170,9 @@ bool LoadAssemblyInto(Module *M, const c
   SMDiagnostic Error;
   bool success =
     nullptr != ParseAssemblyString(assembly, M, Error, M->getContext());
-  std::string errMsg;
-  raw_string_ostream os(errMsg);
-  Error.print("", os);
-  EXPECT_TRUE(success) << os.str();
+  string_ostream errMsg;
+  Error.print("", errMsg);
+  EXPECT_TRUE(success) << errMsg.str();
   return success;
 }
 

Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Wed Jun 25 19:00:48 2014
@@ -458,8 +458,7 @@ void Pattern::PrintFailureInfo(const Sou
   // variable values.
   if (!VariableUses.empty()) {
     for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
-      SmallString<256> Msg;
-      raw_svector_ostream OS(Msg);
+      small_string_ostream<256> OS;
       StringRef Var = VariableUses[i].first;
       if (Var[0] == '@') {
         std::string Value;

Modified: llvm/trunk/utils/TableGen/CodeEmitterGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeEmitterGen.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeEmitterGen.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeEmitterGen.cpp Wed Jun 25 19:00:48 2014
@@ -319,8 +319,7 @@ void CodeEmitterGen::run(raw_ostream &o)
 
   // Default case: unhandled opcode
   o << "  default:\n"
-    << "    std::string msg;\n"
-    << "    raw_string_ostream Msg(msg);\n"
+    << "    string_ostream Msg;\n"
     << "    Msg << \"Not supported instr: \" << MI;\n"
     << "    report_fatal_error(Msg.str());\n"
     << "  }\n"

Modified: llvm/trunk/utils/yaml-bench/YAMLBench.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/yaml-bench/YAMLBench.cpp?rev=211749&r1=211748&r2=211749&view=diff
==============================================================================
--- llvm/trunk/utils/yaml-bench/YAMLBench.cpp (original)
+++ llvm/trunk/utils/yaml-bench/YAMLBench.cpp Wed Jun 25 19:00:48 2014
@@ -166,23 +166,21 @@ static void benchmark( llvm::TimerGroup
 }
 
 static std::string createJSONText(size_t MemoryMB, unsigned ValueSize) {
-  std::string JSONText;
-  llvm::raw_string_ostream Stream(JSONText);
-  Stream << "[\n";
+  llvm::string_ostream OS;
+  OS << "[\n";
   size_t MemoryBytes = MemoryMB * 1024 * 1024;
-  while (JSONText.size() < MemoryBytes) {
-    Stream << " {\n"
-           << "  \"key1\": \"" << std::string(ValueSize, '*') << "\",\n"
-           << "  \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
-           << "  \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
-           << " }";
-    Stream.flush();
-    if (JSONText.size() < MemoryBytes) Stream << ",";
-    Stream << "\n";
+  while (OS.tell() < MemoryBytes) {
+    OS << " {\n"
+       << "  \"key1\": \"" << std::string(ValueSize, '*') << "\",\n"
+       << "  \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
+       << "  \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
+       << " }";
+    if (OS.tell() < MemoryBytes)
+      OS << ",";
+    OS << "\n";
   }
-  Stream << "]\n";
-  Stream.flush();
-  return JSONText;
+  OS << "]\n";
+  return OS.str();
 }
 
 int main(int argc, char **argv) {





More information about the llvm-commits mailing list