Skip to content

Commit

Permalink
[clang] Strip unneeded calls to raw_string_ostream::str() (NFC)
Browse files Browse the repository at this point in the history
Avoid extra layer of indirection.

p.s.
Also, remove calls to raw_string_ostream::flush(), which are no-ops.
  • Loading branch information
JOE1994 committed Sep 14, 2024
1 parent 1d2f727 commit 918972b
Show file tree
Hide file tree
Showing 15 changed files with 11 additions and 19 deletions.
2 changes: 0 additions & 2 deletions clang/tools/clang-refactor/ClangRefactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ class ClangRefactorTool {
<< "' can't be invoked with the given arguments:\n";
for (const auto &Opt : MissingOptions)
OS << " missing '-" << Opt.getKey() << "' option\n";
OS.flush();
return llvm::make_error<llvm::StringError>(
Error, llvm::inconvertibleErrorCode());
}
Expand Down Expand Up @@ -591,7 +590,6 @@ class ClangRefactorTool {
OS << "note: the following actions are supported:\n";
for (const auto &Subcommand : SubCommands)
OS.indent(2) << Subcommand->getName() << "\n";
OS.flush();
return llvm::make_error<llvm::StringError>(
Error, llvm::inconvertibleErrorCode());
}
Expand Down
4 changes: 2 additions & 2 deletions clang/tools/driver/cc1gen_reproducer_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ static std::string generateReproducerMetaInfo(const ClangInvocationInfo &Info) {
OS << '}';
// FIXME: Compare unsaved file hashes and report mismatch in the reproducer.
if (Info.Dump)
llvm::outs() << "REPRODUCER METAINFO: " << OS.str() << "\n";
return std::move(OS.str());
llvm::outs() << "REPRODUCER METAINFO: " << Result << "\n";
return Result;
}

/// Generates a reproducer for a set of arguments from a specific invocation.
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/AST/SourceLocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class WhileParenLocationVerifier : public MatchVerifier<WhileStmt> {
RParenLoc.print(Msg, *Result.SourceManager);
Msg << ">";

this->setFailure(Msg.str());
this->setFailure(MsgStr);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/AST/TemplateNameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ std::string printTemplateName(TemplateName TN, const PrintingPolicy &Policy,
std::string Result;
llvm::raw_string_ostream Out(Result);
TN.print(Out, Policy, Qual);
return Out.str();
return Result;
}

TEST(TemplateName, PrintTemplate) {
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ mutatedBy(const SmallVectorImpl<BoundNodes> &Results, ASTUnit *AST) {
std::string Buffer;
llvm::raw_string_ostream Stream(Buffer);
By->printPretty(Stream, nullptr, AST->getASTContext().getPrintingPolicy());
Chain.emplace_back(StringRef(Stream.str()).trim().str());
Chain.emplace_back(StringRef(Buffer).trim().str());
E = dyn_cast<DeclRefExpr>(By);
}
return Chain;
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Frontend/OutputStreamTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamShared) {

bool Success = ExecuteCompilerInvocation(&Compiler);
EXPECT_FALSE(Success);
EXPECT_TRUE(!VerboseStream.str().empty());
EXPECT_TRUE(!VerboseBuffer.empty());
EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
}

Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/StaticAnalyzer/RangeSetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template <class RangeOrSet> static std::string toString(const RangeOrSet &Obj) {
std::string ObjRepresentation;
llvm::raw_string_ostream SS(ObjRepresentation);
Obj.dump(SS);
return SS.str();
return ObjRepresentation;
}
LLVM_ATTRIBUTE_UNUSED static std::string toString(const llvm::APSInt &Point) {
return toString(Point, 10);
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Tooling/ASTSelectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ TEST(ASTSelectionFinder, CursorAtStartOfFunction) {
std::string DumpValue;
llvm::raw_string_ostream OS(DumpValue);
Node->Children[0].dump(OS);
ASSERT_EQ(OS.str(), "FunctionDecl \"f\" contains-selection\n");
ASSERT_EQ(DumpValue, "FunctionDecl \"f\" contains-selection\n");
});
}

Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Tooling/DiagnosticsYamlTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TEST(DiagnosticsYamlTest, serializesDiagnostics) {
yaml::Output YAML(YamlContentStream);
YAML << TUD;

EXPECT_EQ(YAMLContent, YamlContentStream.str());
EXPECT_EQ(YAMLContent, YamlContent);
}

TEST(DiagnosticsYamlTest, deserializesDiagnostics) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class NamedDeclVisitor
Decl->getNameForDiagnostic(OS,
Decl->getASTContext().getPrintingPolicy(),
true);
Match(OS.str(), Decl->getLocation());
Match(NameWithTemplateArgs, Decl->getLocation());
return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TemplateArgumentLocTraverser
const TemplateArgument &Arg = ArgLoc.getArgument();

Arg.print(Context->getPrintingPolicy(), Stream, /*IncludeType*/ true);
Match(Stream.str(), ArgLoc.getLocation());
Match(ArgStr, ArgLoc.getLocation());
return ExpectedLocationVisitor<TemplateArgumentLocTraverser>::
TraverseTemplateArgumentLoc(ArgLoc);
}
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/Tooling/RefactoringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ static bool checkReplacementError(llvm::Error &&Error,
<< "\n";
}
});
OS.flush();
if (ErrorMessage.empty()) return true;
llvm::errs() << ErrorMessage;
return false;
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/Tooling/RewriterTestContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class RewriterTestContext {
std::string Result;
llvm::raw_string_ostream OS(Result);
Rewrite.getEditBuffer(ID).write(OS);
OS.flush();
return Result;
}

Expand Down
2 changes: 0 additions & 2 deletions clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ void BuiltinNameEmitter::ExtractEnumTypes(ArrayRef<const Record *> Types,
TypesSeen.insert(std::make_pair(T->getValueAsString("Name"), true));
}
}
SS.flush();
}

void BuiltinNameEmitter::EmitDeclarations() {
Expand Down Expand Up @@ -731,7 +730,6 @@ void BuiltinNameEmitter::EmitStringMatcher() {
raw_string_ostream SS(RetStmt);
SS << "return std::make_pair(" << CumulativeIndex << ", " << Ovl.size()
<< ");";
SS.flush();
ValidBuiltins.push_back(
StringMatcher::StringPair(std::string(FctName), RetStmt));
}
Expand Down
2 changes: 0 additions & 2 deletions clang/utils/TableGen/MveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,6 @@ void EmitterBase::EmitBuiltinCG(raw_ostream &OS) {
CodeGenParamAllocator ParamAllocPrelim{&MG.ParamTypes, &OI.ParamValues};
raw_string_ostream OS(MG.Code);
Int.genCode(OS, ParamAllocPrelim, 1);
OS.flush();

MergeableGroupsPrelim[MG].insert(OI);
}
Expand Down Expand Up @@ -1655,7 +1654,6 @@ void EmitterBase::EmitBuiltinCG(raw_ostream &OS) {
&ParamNumbers};
raw_string_ostream OS(MG.Code);
Int->genCode(OS, ParamAlloc, 2);
OS.flush();

MergeableGroups[MG].insert(OI);
}
Expand Down

0 comments on commit 918972b

Please sign in to comment.