[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()`.
This commit is contained in:
Youngsuk Kim 2024-07-05 16:36:19 -05:00
parent dc1da93958
commit 34855405b0
7 changed files with 15 additions and 15 deletions

View File

@ -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;
}

View File

@ -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 {

View File

@ -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,

View File

@ -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.

View File

@ -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) << " ";

View File

@ -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";

View File

@ -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";
}