diff --git a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h --- a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h +++ b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h @@ -32,7 +32,8 @@ std::string Str; llvm::raw_string_ostream OS(Str); S->printPretty(OS, nullptr, PrintingPolicy(ACtx.getLangOpts())); - return OS.str(); + OS.flush(); + return Str; } bool isThisObject(const SymbolicRegion *R) { @@ -67,9 +68,8 @@ std::string VisitLocConcreteInt(loc::ConcreteInt V) { const llvm::APSInt &I = V.getValue(); std::string Str; - llvm::raw_string_ostream OS(Str); - OS << "concrete memory address '" << I << "'"; - return OS.str(); + llvm::raw_string_ostream(Str) << "concrete memory address '" << I << "'"; + return Str; } std::string VisitNonLocSymbolVal(nonloc::SymbolVal V) { @@ -79,10 +79,10 @@ std::string VisitNonLocConcreteInt(nonloc::ConcreteInt V) { const llvm::APSInt &I = V.getValue(); std::string Str; - llvm::raw_string_ostream OS(Str); - OS << (I.isSigned() ? "signed " : "unsigned ") << I.getBitWidth() - << "-bit integer '" << I << "'"; - return OS.str(); + llvm::raw_string_ostream(Str) + << (I.isSigned() ? "signed " : "unsigned ") << I.getBitWidth() + << "-bit integer '" << I << "'"; + return Str; } std::string VisitNonLocLazyCompoundVal(nonloc::LazyCompoundVal V) { @@ -119,11 +119,11 @@ std::string VisitSymIntExpr(const SymIntExpr *S) { std::string Str; - llvm::raw_string_ostream OS(Str); - OS << "(" << Visit(S->getLHS()) << ") " - << std::string(BinaryOperator::getOpcodeStr(S->getOpcode())) << " " - << S->getRHS(); - return OS.str(); + llvm::raw_string_ostream(Str) + << "(" << Visit(S->getLHS()) << ") " + << std::string(BinaryOperator::getOpcodeStr(S->getOpcode())) << " " + << S->getRHS(); + return Str; } // TODO: IntSymExpr doesn't appear in practice. @@ -177,7 +177,8 @@ else OS << "'" << Visit(R->getIndex()) << "'"; OS << " of " + Visit(R->getSuperRegion()); - return OS.str(); + OS.flush(); + return Str; } std::string VisitNonParamVarRegion(const NonParamVarRegion *R) { diff --git a/clang/include/clang/Testing/TestClangConfig.h b/clang/include/clang/Testing/TestClangConfig.h --- a/clang/include/clang/Testing/TestClangConfig.h +++ b/clang/include/clang/Testing/TestClangConfig.h @@ -71,9 +71,9 @@ std::string toString() const { std::string Result; - llvm::raw_string_ostream OS(Result); - OS << "{ Language=" << Language << ", Target=" << Target << " }"; - return OS.str(); + llvm::raw_string_ostream(Result) + << "{ Language=" << Language << ", Target=" << Target << " }"; + return Result; } friend std::ostream &operator<<(std::ostream &OS, diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp --- a/clang/lib/AST/ASTDiagnostic.cpp +++ b/clang/lib/AST/ASTDiagnostic.cpp @@ -307,12 +307,12 @@ // type and element count. if (const auto *VTy = Ty->getAs()) { std::string DecoratedString; - llvm::raw_string_ostream OS(DecoratedString); const char *Values = VTy->getNumElements() > 1 ? "values" : "value"; - OS << "'" << S << "' (vector of " << VTy->getNumElements() << " '" - << VTy->getElementType().getAsString(Context.getPrintingPolicy()) - << "' " << Values << ")"; - return OS.str(); + llvm::raw_string_ostream(DecoratedString) + << "'" << S << "' (vector of " << VTy->getNumElements() << " '" + << VTy->getElementType().getAsString(Context.getPrintingPolicy()) + << "' " << Values << ")"; + return DecoratedString; } } diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp --- a/clang/lib/AST/AttrImpl.cpp +++ b/clang/lib/AST/AttrImpl.cpp @@ -60,7 +60,8 @@ else OS << "disable"; OS << ")"; - return OS.str(); + OS.flush(); + return ValueName; } // Return a string suitable for identifying this attribute in diagnostics. diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1589,7 +1589,8 @@ std::string QualName; llvm::raw_string_ostream OS(QualName); printQualifiedName(OS, getASTContext().getPrintingPolicy()); - return OS.str(); + OS.flush(); + return QualName; } void NamedDecl::printQualifiedName(raw_ostream &OS) const { diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp --- a/clang/lib/AST/DeclarationName.cpp +++ b/clang/lib/AST/DeclarationName.cpp @@ -234,9 +234,8 @@ std::string DeclarationName::getAsString() const { std::string Result; - llvm::raw_string_ostream OS(Result); - OS << *this; - return OS.str(); + llvm::raw_string_ostream(Result) << *this; + return Result; } void *DeclarationName::getFETokenInfoSlow() const { @@ -458,9 +457,8 @@ std::string DeclarationNameInfo::getAsString() const { std::string Result; - llvm::raw_string_ostream OS(Result); - OS << *this; - return OS.str(); + llvm::raw_string_ostream(Result) << *this; + return Result; } raw_ostream &clang::operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo) { diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -2454,7 +2454,8 @@ Property.RawString); } } - return OS.str(); + OS.flush(); + return MangledName; } OMPTraitInfo::OMPTraitInfo(StringRef MangledName) { diff --git a/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp b/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp --- a/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp @@ -204,7 +204,8 @@ std::string S; llvm::raw_string_ostream OS(S); printToStream(OS); - return OS.str(); + OS.flush(); + return S; } void Diagnostics::printToStreamFull(llvm::raw_ostream &OS) const { @@ -223,7 +224,8 @@ std::string S; llvm::raw_string_ostream OS(S); printToStreamFull(OS); - return OS.str(); + OS.flush(); + return S; } } // namespace dynamic diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp --- a/clang/lib/Analysis/AnalysisDeclContext.cpp +++ b/clang/lib/Analysis/AnalysisDeclContext.cpp @@ -387,7 +387,8 @@ OS << ' ' << OMD->getSelector().getAsString() << ']'; } - return OS.str(); + OS.flush(); + return Str; } LocationContextManager &AnalysisDeclContext::getLocationContextManager() { diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -90,7 +90,8 @@ std::string S; llvm::raw_string_ostream OS(S); print(OS, SM); - return OS.str(); + OS.flush(); + return S; } LLVM_DUMP_METHOD void SourceLocation::dump(const SourceManager &SM) const { @@ -149,7 +150,8 @@ std::string S; llvm::raw_string_ostream OS(S); print(OS, SM); - return OS.str(); + OS.flush(); + return S; } //===----------------------------------------------------------------------===// diff --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp --- a/clang/lib/Basic/Version.cpp +++ b/clang/lib/Basic/Version.cpp @@ -82,7 +82,8 @@ OS << LLVMRepo << ' '; OS << LLVMRev << ')'; } - return OS.str(); + OS.flush(); + return buf; } std::string getClangFullVersion() { @@ -102,7 +103,8 @@ OS << " " << repo; } - return OS.str(); + OS.flush(); + return buf; } std::string getClangFullCPPVersion() { @@ -120,7 +122,8 @@ OS << " " << repo; } - return OS.str(); + OS.flush(); + return buf; } } // end namespace clang diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1285,7 +1285,8 @@ std::string Buffer; llvm::raw_string_ostream OS(Buffer); llvm::interleave(BundleParts, OS, [&OS](StringRef Part) { OS << Part; }, ","); - return OS.str(); + OS.flush(); + return Buffer; } // Set the profile kind using fprofile-instrument-use-path. diff --git a/clang/lib/Frontend/TestModuleFileExtension.cpp b/clang/lib/Frontend/TestModuleFileExtension.cpp --- a/clang/lib/Frontend/TestModuleFileExtension.cpp +++ b/clang/lib/Frontend/TestModuleFileExtension.cpp @@ -130,8 +130,8 @@ std::string TestModuleFileExtension::str() const { std::string Buffer; - llvm::raw_string_ostream OS(Buffer); - OS << BlockName << ":" << MajorVersion << ":" << MinorVersion << ":" << Hashed - << ":" << UserInfo; - return OS.str(); + llvm::raw_string_ostream(Buffer) + << BlockName << ":" << MajorVersion << ":" << MinorVersion << ":" + << Hashed << ":" << UserInfo; + return Buffer; } diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp --- a/clang/lib/Rewrite/HTMLRewrite.cpp +++ b/clang/lib/Rewrite/HTMLRewrite.cpp @@ -202,8 +202,8 @@ case '&': os << "&"; break; } } - - return os.str(); + os.flush(); + return Str; } static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo, diff --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp --- a/clang/lib/Sema/CodeCompleteConsumer.cpp +++ b/clang/lib/Sema/CodeCompleteConsumer.cpp @@ -335,7 +335,8 @@ break; } } - return OS.str(); + OS.flush(); + return Result; } const char *CodeCompletionString::getTypedText() const { @@ -640,7 +641,8 @@ break; } } - return OS.str(); + OS.flush(); + return Result; } void PrintingCodeCompleteConsumer::ProcessOverloadCandidates( diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -792,7 +792,8 @@ OS << (I.index() == Rules.size() - 1 ? ", and " : ", "); OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'"; } - return OS.str(); + OS.flush(); + return Result; } } // end anonymous namespace diff --git a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp @@ -386,10 +386,10 @@ auto *PathBR = static_cast(&BR); if (auto IsInteresting = PathBR->getInterestingnessKind(RetSym)) { std::string SBuf; - llvm::raw_string_ostream OS(SBuf); - OS << "Function '" << FuncDecl->getDeclName() - << "' returns an open handle"; - return OS.str(); + llvm::raw_string_ostream(SBuf) + << "Function '" << FuncDecl->getDeclName() + << "' returns an open handle"; + return SBuf; } else return ""; }); @@ -402,10 +402,10 @@ auto *PathBR = static_cast(&BR); if (auto IsInteresting = PathBR->getInterestingnessKind(RetSym)) { std::string SBuf; - llvm::raw_string_ostream OS(SBuf); - OS << "Function '" << FuncDecl->getDeclName() - << "' returns an unowned handle"; - return OS.str(); + llvm::raw_string_ostream(SBuf) + << "Function '" << FuncDecl->getDeclName() + << "' returns an unowned handle"; + return SBuf; } else return ""; }); @@ -436,10 +436,10 @@ auto *PathBR = static_cast(&BR); if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) { std::string SBuf; - llvm::raw_string_ostream OS(SBuf); - OS << "Handle released through " << ParamDiagIdx - << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter"; - return OS.str(); + llvm::raw_string_ostream(SBuf) + << "Handle released through " << ParamDiagIdx + << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter"; + return SBuf; } else return ""; }); @@ -450,10 +450,10 @@ auto *PathBR = static_cast(&BR); if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) { std::string SBuf; - llvm::raw_string_ostream OS(SBuf); - OS << "Handle allocated through " << ParamDiagIdx - << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter"; - return OS.str(); + llvm::raw_string_ostream(SBuf) + << "Handle allocated through " << ParamDiagIdx + << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter"; + return SBuf; } else return ""; }); @@ -464,10 +464,10 @@ auto *PathBR = static_cast(&BR); if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) { std::string SBuf; - llvm::raw_string_ostream OS(SBuf); - OS << "Unowned handle allocated through " << ParamDiagIdx - << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter"; - return OS.str(); + llvm::raw_string_ostream(SBuf) + << "Unowned handle allocated through " << ParamDiagIdx + << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter"; + return SBuf; } else return ""; }); diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp --- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -437,7 +437,8 @@ for (auto BI : *Buf) os << BI; - return os.str(); + os.flush(); + return file; } void HTMLDiagnostics::dumpCoverageData( @@ -534,7 +535,8 @@ )<<<"; - return os.str(); + os.flush(); + return s; } void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, @@ -1200,9 +1202,9 @@ std::string getSpanBeginForControl(const char *ClassName, unsigned Index) { std::string Result; - llvm::raw_string_ostream OS(Result); - OS << ""; - return OS.str(); + llvm::raw_string_ostream(Result) + << ""; + return Result; } std::string getSpanBeginForControlStart(unsigned Index) { diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -444,7 +444,8 @@ std::string s; llvm::raw_string_ostream os(s); dumpToStream(os); - return os.str(); + os.flush(); + return s; } void MemRegion::dumpToStream(raw_ostream &os) const { diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp --- a/clang/lib/Tooling/Syntax/Tokens.cpp +++ b/clang/lib/Tooling/Syntax/Tokens.cpp @@ -927,5 +927,6 @@ M.EndExpanded); } } - return OS.str(); + OS.flush(); + return Dump; } diff --git a/clang/lib/Tooling/Syntax/Tree.cpp b/clang/lib/Tooling/Syntax/Tree.cpp --- a/clang/lib/Tooling/Syntax/Tree.cpp +++ b/clang/lib/Tooling/Syntax/Tree.cpp @@ -263,7 +263,8 @@ OS << " "; } }); - return OS.str(); + OS.flush(); + return Storage; } void syntax::Node::assertInvariants() const { diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp --- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp +++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp @@ -139,7 +139,8 @@ Passes.run(*M); - return OS.str(); + OS.flush(); + return outString; } // Takes a function and runs it on a set of inputs diff --git a/clang/unittests/AST/ASTTraverserTest.cpp b/clang/unittests/AST/ASTTraverserTest.cpp --- a/clang/unittests/AST/ASTTraverserTest.cpp +++ b/clang/unittests/AST/ASTTraverserTest.cpp @@ -111,7 +111,8 @@ Dumper.Visit(std::forward(N)...); - return OS.str(); + OS.flush(); + return Buffer; } template @@ -126,7 +127,8 @@ Dumper.Visit(std::forward(N)...); - return OS.str(); + OS.flush(); + return Buffer; } const FunctionDecl *getFunctionNode(clang::ASTUnit *AST, diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp b/clang/unittests/Analysis/MacroExpansionContextTest.cpp --- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp +++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp @@ -95,14 +95,16 @@ std::string Buf; llvm::raw_string_ostream OS{Buf}; Ctx.dumpExpandedTextsToStream(OS); - return OS.str(); + OS.flush(); + return Buf; } static std::string dumpExpansionRanges(const MacroExpansionContext &Ctx) { std::string Buf; llvm::raw_string_ostream OS{Buf}; Ctx.dumpExpansionRangesToStream(OS); - return OS.str(); + OS.flush(); + return Buf; } }; diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp --- a/clang/unittests/Tooling/Syntax/TreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -203,7 +203,8 @@ OS << "]"; - return OS.str(); + OS.flush(); + return Storage; } std::string dumpNodes(ArrayRef Nodes) { @@ -218,7 +219,8 @@ OS << "]"; - return OS.str(); + OS.flush(); + return Storage; } };