From 255907042245b77779e3e38c5ce66901866cabe5 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Thu, 26 Jun 2014 00:00:48 +0000 Subject: 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 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 --- lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/Transforms/ObjCARC') diff --git a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index dd4dd50f0b..744fb24048 100644 --- a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -835,8 +835,7 @@ static MDString *AppendMDNodeToSourcePtr(unsigned NodeId, // 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(unsigned NodeId, Hash = cast(Node->getOperand(0)); } } else if (Argument *Arg = dyn_cast(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(unsigned NodeId, } static std::string SequenceToString(Sequence A) { - std::string str; - raw_string_ostream os(str); + string_ostream os; os << A; return os.str(); } -- cgit v1.2.3