aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungsuk Kim <youngsuk.kim@hpe.com>2024-07-05 16:36:19 -0500
committerYoungsuk Kim <youngsuk.kim@hpe.com>2024-07-05 17:22:03 -0500
commit34855405b0a7dd6719fa3278f9b888f7f11bc4d8 (patch)
treea50a20f8ede8cf68f4972d163cbb638d712970a5
parentdc1da93958be0311b79dce39d71bd954c478cf19 (diff)
downloadllvm-34855405b0a7dd6719fa3278f9b888f7f11bc4d8.zip
llvm-34855405b0a7dd6719fa3278f9b888f7f11bc4d8.tar.gz
llvm-34855405b0a7dd6719fa3278f9b888f7f11bc4d8.tar.bz2
[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()`.
-rw-r--r--llvm/lib/CodeGen/MIRPrintingPass.cpp2
-rw-r--r--llvm/lib/FileCheck/FileCheck.cpp2
-rw-r--r--llvm/lib/IR/DiagnosticInfo.cpp2
-rw-r--r--llvm/lib/Remarks/Remark.cpp2
-rw-r--r--llvm/tools/llvm-opt-report/OptReport.cpp8
-rw-r--r--llvm/utils/TableGen/CompressInstEmitter.cpp10
-rw-r--r--llvm/utils/TableGen/X86DisassemblerTables.cpp4
7 files changed, 15 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/MIRPrintingPass.cpp b/llvm/lib/CodeGen/MIRPrintingPass.cpp
index 0aed129..f70c073 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 1eb8330..df5f7f4 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 108bf68..623f372 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 ef42271..0e98cad 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 27dcb88..cee9abc 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 fcf7793..1e30f05 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 f4d282f..7d28c48 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";
}