Skip to content

Commit caf26b9

Browse files
authored
[llvm][utils] Avoid 'raw_string_ostream::str()' (NFC) (#97160)
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 comment to remove `raw_string_ostream::str()`.
1 parent 56ef6a2 commit caf26b9

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

llvm/utils/FileCheck/FileCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static void DumpAnnotatedInput(raw_ostream &OS, const FileCheckRequest &Req,
641641
LineOS = &ElidedLinesOS;
642642
else {
643643
LineOS = &OS;
644-
DumpEllipsisOrElidedLines(OS, ElidedLinesOS.str(), LabelWidth);
644+
DumpEllipsisOrElidedLines(OS, ElidedLines, LabelWidth);
645645
}
646646

647647
// Print right-aligned line number.
@@ -723,7 +723,7 @@ static void DumpAnnotatedInput(raw_ostream &OS, const FileCheckRequest &Req,
723723
++AnnotationItr;
724724
}
725725
}
726-
DumpEllipsisOrElidedLines(OS, ElidedLinesOS.str(), LabelWidth);
726+
DumpEllipsisOrElidedLines(OS, ElidedLines, LabelWidth);
727727

728728
OS << ">>>>>>\n";
729729
}

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,10 +2367,10 @@ emitConvertFuncs(CodeGenTarget &Target, StringRef ClassName,
23672367
OS << "};\n\n";
23682368

23692369
// Spit out the conversion driver function.
2370-
OS << CvtOS.str();
2370+
OS << ConvertFnBody;
23712371

23722372
// Spit out the operand number lookup function.
2373-
OS << OpOS.str();
2373+
OS << OperandFnBody;
23742374

23752375
return ConversionTable.size();
23762376
}

llvm/utils/TableGen/AsmWriterEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,8 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
11621162
PatternCount - PatternStart);
11631163
}
11641164

1165-
if (OpcodeO.str().empty()) {
1166-
O << HeaderO.str();
1165+
if (PatternsForOpcode.empty()) {
1166+
O << Header;
11671167
O << " return false;\n";
11681168
O << "}\n\n";
11691169
O << "#endif // PRINT_ALIAS_INSTR\n";
@@ -1177,15 +1177,15 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
11771177
<< " const MCSubtargetInfo &STI,\n"
11781178
<< " unsigned PredicateIndex);\n";
11791179

1180-
O << HeaderO.str();
1180+
O << Header;
11811181
O.indent(2) << "static const PatternsForOpcode OpToPatterns[] = {\n";
1182-
O << OpcodeO.str();
1182+
O << PatternsForOpcode;
11831183
O.indent(2) << "};\n\n";
11841184
O.indent(2) << "static const AliasPattern Patterns[] = {\n";
1185-
O << PatternO.str();
1185+
O << Patterns;
11861186
O.indent(2) << "};\n\n";
11871187
O.indent(2) << "static const AliasPatternCond Conds[] = {\n";
1188-
O << CondO.str();
1188+
O << Conds;
11891189
O.indent(2) << "};\n\n";
11901190
O.indent(2) << "static const char AsmStrings[] =\n";
11911191
for (const auto &P : AsmStrings) {

llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void VarLenCodeEmitterGen::emitInstructionBaseValues(
405405
IS.indent(4) << "{/*NumBits*/0, /*Index*/0}\n };\n";
406406
SS.indent(4) << "UINT64_C(0)\n };\n";
407407

408-
OS << IS.str() << SS.str();
408+
OS << IndexArray << StorageArray;
409409
}
410410

411411
std::string VarLenCodeEmitterGen::getInstructionCases(Record *R,

0 commit comments

Comments
 (0)