[llvm] 3485540 - [llvm] Avoid 'raw_string_ostream::str' (NFC)
Youngsuk Kim via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 15:27:31 PDT 2024
Author: Youngsuk Kim
Date: 2024-07-05T17:22:03-05:00
New Revision: 34855405b0a7dd6719fa3278f9b888f7f11bc4d8
URL: https://github.com/llvm/llvm-project/commit/34855405b0a7dd6719fa3278f9b888f7f11bc4d8
DIFF: https://github.com/llvm/llvm-project/commit/34855405b0a7dd6719fa3278f9b888f7f11bc4d8.diff
LOG: [llvm] Avoid 'raw_string_ostream::str' (NFC)
Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.
Work towards TODO item to remove `raw_string_ostream::str()`.
Added:
Modified:
llvm/lib/CodeGen/MIRPrintingPass.cpp
llvm/lib/FileCheck/FileCheck.cpp
llvm/lib/IR/DiagnosticInfo.cpp
llvm/lib/Remarks/Remark.cpp
llvm/tools/llvm-opt-report/OptReport.cpp
llvm/utils/TableGen/CompressInstEmitter.cpp
llvm/utils/TableGen/X86DisassemblerTables.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MIRPrintingPass.cpp b/llvm/lib/CodeGen/MIRPrintingPass.cpp
index 0aed1297cd3ea..f70c0731ffafa 100644
--- a/llvm/lib/CodeGen/MIRPrintingPass.cpp
+++ b/llvm/lib/CodeGen/MIRPrintingPass.cpp
@@ -52,7 +52,7 @@ struct MIRPrintingPass : public MachineFunctionPass {
std::string Str;
raw_string_ostream StrOS(Str);
printMIR(StrOS, MF);
- MachineFunctions.append(StrOS.str());
+ MachineFunctions.append(Str);
return false;
}
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 1eb8330232321..df5f7f4697c5c 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1488,7 +1488,7 @@ std::string Check::FileCheckType::getModifiersDescription() const {
if (isLiteralMatch())
OS << "LITERAL";
OS << '}';
- return OS.str();
+ return Ret;
}
std::string Check::FileCheckType::getDescription(StringRef Prefix) const {
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp
index 108bf68900595..623f372bb9e74 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -403,7 +403,7 @@ std::string DiagnosticInfoOptimizationBase::getMsg() const {
? Args.end()
: Args.begin() + FirstExtraArgIndex))
OS << Arg.Val;
- return OS.str();
+ return Str;
}
DiagnosticInfoMisExpect::DiagnosticInfoMisExpect(const Instruction *Inst,
diff --git a/llvm/lib/Remarks/Remark.cpp b/llvm/lib/Remarks/Remark.cpp
index ef42271a3c8da..0e98cad8e9045 100644
--- a/llvm/lib/Remarks/Remark.cpp
+++ b/llvm/lib/Remarks/Remark.cpp
@@ -23,7 +23,7 @@ std::string Remark::getArgsAsMsg() const {
raw_string_ostream OS(Str);
for (const Argument &Arg : Args)
OS << Arg.Val;
- return OS.str();
+ return Str;
}
/// Returns the value of a specified key parsed from StringRef.
diff --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp
index 27dcb88134bd8..cee9abcb49419 100644
--- a/llvm/tools/llvm-opt-report/OptReport.cpp
+++ b/llvm/tools/llvm-opt-report/OptReport.cpp
@@ -370,10 +370,10 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
if (!Succinct) {
RS << LLI.UnrollCount;
- RS << std::string(UCDigits - RS.str().size(), ' ');
+ RS << std::string(UCDigits - R.size(), ' ');
}
- return RS.str();
+ return R;
};
auto VStr = [VFDigits,
@@ -383,10 +383,10 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
if (!Succinct) {
RS << LLI.VectorizationFactor << "," << LLI.InterleaveCount;
- RS << std::string(VFDigits + ICDigits + 1 - RS.str().size(), ' ');
+ RS << std::string(VFDigits + ICDigits + 1 - R.size(), ' ');
}
- return RS.str();
+ return R;
};
OS << llvm::format_decimal(L, LNDigits) << " ";
diff --git a/llvm/utils/TableGen/CompressInstEmitter.cpp b/llvm/utils/TableGen/CompressInstEmitter.cpp
index fcf77934faacf..1e30f052ab1df 100644
--- a/llvm/utils/TableGen/CompressInstEmitter.cpp
+++ b/llvm/utils/TableGen/CompressInstEmitter.cpp
@@ -618,7 +618,7 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
}
if (CompressPatterns.empty()) {
- OS << FuncH.str();
+ OS << FH;
OS.indent(2) << "return false;\n}\n";
if (EType == EmitterType::Compress)
OS << "\n#endif //GEN_COMPRESS_INSTR\n";
@@ -835,10 +835,10 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
}
if (CompressOrUncompress)
CodeStream.indent(6) << "OutInst.setLoc(MI.getLoc());\n";
- mergeCondAndCode(CaseStream, CondStream.str(), CodeStream.str());
+ mergeCondAndCode(CaseStream, CondString, CodeString);
PrevOp = CurOp;
}
- Func << CaseStream.str() << "\n";
+ Func << CaseString << "\n";
// Close brace for the last case.
Func.indent(4) << "} // case " << CurOp << "\n";
Func.indent(2) << "} // switch\n";
@@ -876,8 +876,8 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
<< "}\n\n";
}
- OS << FuncH.str();
- OS << Func.str();
+ OS << FH;
+ OS << F;
if (EType == EmitterType::Compress)
OS << "\n#endif //GEN_COMPRESS_INSTR\n";
diff --git a/llvm/utils/TableGen/X86DisassemblerTables.cpp b/llvm/utils/TableGen/X86DisassemblerTables.cpp
index f4d282f54ac05..7d28c48055c34 100644
--- a/llvm/utils/TableGen/X86DisassemblerTables.cpp
+++ b/llvm/utils/TableGen/X86DisassemblerTables.cpp
@@ -1062,11 +1062,11 @@ void DisassemblerTables::emit(raw_ostream &o) const {
i1--;
emitContextDecisions(o1, o2, i1, i2, ModRMTableNum);
- o << o1.str();
+ o << s1;
o << " 0x0\n";
o << "};\n";
o << "\n";
- o << o2.str();
+ o << s2;
o << "\n";
o << "\n";
}
More information about the llvm-commits
mailing list