[llvm] [NFC][LLVM] Override and deprecate `raw_string_ostream::flush` (PR #164086)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 18 06:50:37 PDT 2025
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/164086
>From cf604b27c85829ac2c5cb862b3adf75d4e21c4de Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sat, 18 Oct 2025 06:44:13 -0700
Subject: [PATCH] [NFC][LLVM] Override and deprecate
`raw_string_ostream::flush`
---
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 3 ---
llvm/include/llvm/Analysis/LazyCallGraph.h | 2 --
llvm/include/llvm/Support/FormatVariadic.h | 1 -
llvm/include/llvm/Support/InterleavedRange.h | 1 -
llvm/include/llvm/Support/raw_ostream.h | 2 ++
llvm/lib/Analysis/ImportedFunctionsInliningStatistics.cpp | 1 -
llvm/lib/CodeGen/MIRCanonicalizerPass.cpp | 1 -
llvm/lib/CodeGen/MachineBlockPlacement.cpp | 1 -
llvm/lib/CodeGen/ModuloSchedule.cpp | 1 -
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 2 --
llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 1 -
llvm/lib/DebugInfo/GSYM/GsymCreator.cpp | 1 -
llvm/lib/IR/Attributes.cpp | 4 ----
llvm/lib/IR/Core.cpp | 8 --------
llvm/lib/IR/Mangler.cpp | 2 --
llvm/lib/Object/Archive.cpp | 3 ---
llvm/lib/Object/ArchiveWriter.cpp | 2 --
llvm/lib/Object/IRSymtab.cpp | 2 --
llvm/lib/ObjectYAML/DWARFEmitter.cpp | 1 -
llvm/lib/ObjectYAML/WasmEmitter.cpp | 5 -----
llvm/lib/Remarks/YAMLRemarkParser.cpp | 1 -
llvm/lib/Support/Chrono.cpp | 1 -
22 files changed, 2 insertions(+), 44 deletions(-)
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index c9de5a4fa9213..b431229812297 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1813,7 +1813,6 @@ struct BFIDOTGraphTraitsBase : public DefaultDOTGraphTraits {
raw_string_ostream OS(Result);
OS << "color=\"red\"";
- OS.flush();
return Result;
}
@@ -1872,8 +1871,6 @@ struct BFIDOTGraphTraitsBase : public DefaultDOTGraphTraits {
OS << ",color=\"red\"";
}
}
-
- OS.flush();
return Str;
}
};
diff --git a/llvm/include/llvm/Analysis/LazyCallGraph.h b/llvm/include/llvm/Analysis/LazyCallGraph.h
index 80ee72b72836d..f042f17dee2e3 100644
--- a/llvm/include/llvm/Analysis/LazyCallGraph.h
+++ b/llvm/include/llvm/Analysis/LazyCallGraph.h
@@ -513,7 +513,6 @@ class LazyCallGraph {
std::string Name;
raw_string_ostream OS(Name);
OS << *this;
- OS.flush();
return Name;
}
};
@@ -654,7 +653,6 @@ class LazyCallGraph {
std::string Name;
raw_string_ostream OS(Name);
OS << *this;
- OS.flush();
return Name;
}
diff --git a/llvm/include/llvm/Support/FormatVariadic.h b/llvm/include/llvm/Support/FormatVariadic.h
index 85652924491ba..5dab6a642c435 100644
--- a/llvm/include/llvm/Support/FormatVariadic.h
+++ b/llvm/include/llvm/Support/FormatVariadic.h
@@ -105,7 +105,6 @@ class formatv_object_base {
std::string Result;
raw_string_ostream Stream(Result);
Stream << *this;
- Stream.flush();
return Result;
}
diff --git a/llvm/include/llvm/Support/InterleavedRange.h b/llvm/include/llvm/Support/InterleavedRange.h
index ce7cac98bcdd4..8f43ec1891dcd 100644
--- a/llvm/include/llvm/Support/InterleavedRange.h
+++ b/llvm/include/llvm/Support/InterleavedRange.h
@@ -56,7 +56,6 @@ template <typename Range> class InterleavedRange {
std::string Result;
raw_string_ostream Stream(Result);
Stream << *this;
- Stream.flush();
return Result;
}
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 70916d8e4adb0..92315282d699f 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -682,6 +682,8 @@ class LLVM_ABI raw_string_ostream : public raw_ostream {
void reserveExtraSpace(uint64_t ExtraSize) override {
OS.reserve(tell() + ExtraSize);
}
+
+ void flush() = delete;
};
/// A raw_ostream that writes to an SmallVector or SmallString. This is a
diff --git a/llvm/lib/Analysis/ImportedFunctionsInliningStatistics.cpp b/llvm/lib/Analysis/ImportedFunctionsInliningStatistics.cpp
index 61715c466ae85..f550cd6e1c68e 100644
--- a/llvm/lib/Analysis/ImportedFunctionsInliningStatistics.cpp
+++ b/llvm/lib/Analysis/ImportedFunctionsInliningStatistics.cpp
@@ -167,7 +167,6 @@ void ImportedFunctionsInliningStatistics::dump(const bool Verbose) {
"non-imported functions inlined into importing module",
InlinedNotImportedFunctionsToImportingModuleCount,
NotImportedFuncCount, "non-imported functions");
- Ostream.flush();
dbgs() << Out;
}
diff --git a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
index 7c1264e279f66..3f954da8ef319 100644
--- a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
+++ b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
@@ -96,7 +96,6 @@ rescheduleLexographically(std::vector<MachineInstr *> instructions,
std::string S;
raw_string_ostream OS(S);
II->print(OS);
- OS.flush();
// Trim the assignment, or start from the beginning in the case of a store.
const size_t i = S.find('=');
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index e9c75f0753f89..f8176e225d313 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -700,7 +700,6 @@ static std::string getBlockName(const MachineBasicBlock *BB) {
raw_string_ostream OS(Result);
OS << printMBBReference(*BB);
OS << " ('" << BB->getName() << "')";
- OS.flush();
return Result;
}
#endif
diff --git a/llvm/lib/CodeGen/ModuloSchedule.cpp b/llvm/lib/CodeGen/ModuloSchedule.cpp
index d47ed65540cf4..a8bc4dd62290b 100644
--- a/llvm/lib/CodeGen/ModuloSchedule.cpp
+++ b/llvm/lib/CodeGen/ModuloSchedule.cpp
@@ -2033,7 +2033,6 @@ void PeelingModuloScheduleExpander::validateAgainstModuloScheduleExpander() {
std::string ScheduleDump;
raw_string_ostream OS(ScheduleDump);
Schedule.print(OS);
- OS.flush();
// First, run the normal ModuleScheduleExpander. We don't support any
// InstrChanges.
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index ae681b9aebdfb..9292cd42c3d6b 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1953,7 +1953,6 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
raw_string_ostream OS(Flags);
emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(),
getMangler());
- OS.flush();
if (!Flags.empty()) {
Streamer.switchSection(getDrectveSection());
Streamer.emitBytes(Flags);
@@ -1978,7 +1977,6 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
raw_string_ostream OS(Flags);
emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(),
getMangler());
- OS.flush();
if (!Flags.empty()) {
Streamer.switchSection(getDrectveSection());
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 5ab80e339a1ad..aba8cc3455872 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -234,7 +234,6 @@ bool DWARFVerifier::verifyName(const DWARFDie &Die) {
raw_string_ostream OS(ReconstructedName);
std::string OriginalFullName;
Die.getFullName(OS, &OriginalFullName);
- OS.flush();
if (OriginalFullName.empty() || OriginalFullName == ReconstructedName)
return false;
diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index 93ff3b924db32..dbfebd8f2fd36 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -564,7 +564,6 @@ llvm::Error GsymCreator::saveSegments(StringRef Path,
std::optional<uint64_t> FirstFuncAddr = GC->getFirstFunctionAddress();
if (FirstFuncAddr) {
SGP << Path << "-" << llvm::format_hex(*FirstFuncAddr, 1);
- SGP.flush();
Err = GC->save(SegmentedGsymPath, ByteOrder, std::nullopt);
if (Err)
return Err;
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 4ac2ebd55dcac..291361cedc95d 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -544,7 +544,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
Result += '(';
raw_string_ostream OS(Result);
getValueAsType()->print(OS, false, true);
- OS.flush();
Result += ')';
return Result;
}
@@ -660,7 +659,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
OS << getModRefStr(MR);
}
OS << ")";
- OS.flush();
return Result;
}
@@ -686,7 +684,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
OS << "i" << CR.getBitWidth() << " ";
OS << CR.getLower() << ", " << CR.getUpper();
OS << ")";
- OS.flush();
return Result;
}
@@ -697,7 +694,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
OS << "initializes(";
CRL.print(OS);
OS << ")";
- OS.flush();
return Result;
}
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 27d8294b01264..ccb685d6bf014 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -245,7 +245,6 @@ char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
DiagnosticPrinterRawOStream DP(Stream);
unwrap(DI)->print(DP);
- Stream.flush();
return LLVMCreateMessage(MsgStorage.c_str());
}
@@ -473,7 +472,6 @@ char *LLVMPrintModuleToString(LLVMModuleRef M) {
raw_string_ostream os(buf);
unwrap(M)->print(os, nullptr);
- os.flush();
return strdup(buf.c_str());
}
@@ -651,8 +649,6 @@ char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
else
os << "Printing <null> Type";
- os.flush();
-
return strdup(buf.c_str());
}
@@ -1046,8 +1042,6 @@ char* LLVMPrintValueToString(LLVMValueRef Val) {
else
os << "Printing <null> Value";
- os.flush();
-
return strdup(buf.c_str());
}
@@ -1064,8 +1058,6 @@ char *LLVMPrintDbgRecordToString(LLVMDbgRecordRef Record) {
else
os << "Printing <null> DbgRecord";
- os.flush();
-
return strdup(buf.c_str());
}
diff --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp
index 55c825d272a2f..43e8485434d9d 100644
--- a/llvm/lib/IR/Mangler.cpp
+++ b/llvm/lib/IR/Mangler.cpp
@@ -227,7 +227,6 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
std::string Flag;
raw_string_ostream FlagOS(Flag);
Mangler.getNameWithPrefix(FlagOS, GV, false);
- FlagOS.flush();
if (Flag[0] == GV->getDataLayout().getGlobalPrefix())
OS << Flag.substr(1);
else
@@ -266,7 +265,6 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
std::string Flag;
raw_string_ostream FlagOS(Flag);
Mangler.getNameWithPrefix(FlagOS, GV, false);
- FlagOS.flush();
if (Flag[0] == GV->getDataLayout().getGlobalPrefix())
OS << Flag.substr(1);
else
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index 861c284253f7a..e63d8fd1e7d0c 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -110,7 +110,6 @@ ArchiveMemberHeader::ArchiveMemberHeader(const Archive *Parent,
raw_string_ostream OS(Buf);
OS.write_escaped(
StringRef(ArMemHdr->Terminator, sizeof(ArMemHdr->Terminator)));
- OS.flush();
std::string Msg("terminator characters in archive member \"" + Buf +
"\" not the correct \"`\\n\" values for the archive "
"member header ");
@@ -281,7 +280,6 @@ Expected<StringRef> ArchiveMemberHeader::getName(uint64_t Size) const {
std::string Buf;
raw_string_ostream OS(Buf);
OS.write_escaped(Name.substr(1).rtrim(' '));
- OS.flush();
uint64_t ArchiveOffset =
reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
return malformedError("long name offset characters after the '/' are "
@@ -320,7 +318,6 @@ Expected<StringRef> ArchiveMemberHeader::getName(uint64_t Size) const {
std::string Buf;
raw_string_ostream OS(Buf);
OS.write_escaped(Name.substr(3).rtrim(' '));
- OS.flush();
uint64_t ArchiveOffset =
reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
return malformedError("long name length characters after the #1/ are "
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index a11259748b9cc..6d2bbca179836 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -347,7 +347,6 @@ static MemberData computeStringTable(StringRef Names) {
printWithSpacePadding(Out, "//", 48);
printWithSpacePadding(Out, Size + Pad, 10);
Out << "`\n";
- Out.flush();
return {{}, std::move(Header), Names, Pad ? "\n" : ""};
}
@@ -959,7 +958,6 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
printMemberHeader(Out, Pos, StringTable, MemberNames, Kind, Thin, *M,
ModTime, Size);
}
- Out.flush();
std::vector<unsigned> Symbols;
if (NeedSymbols != SymtabWritingMode::NoSymtab) {
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp
index a45b34eb2e706..20610262f6a1c 100644
--- a/llvm/lib/Object/IRSymtab.cpp
+++ b/llvm/lib/Object/IRSymtab.cpp
@@ -317,7 +317,6 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
std::string FallbackName;
raw_string_ostream OS(FallbackName);
Msymtab.printSymbolName(OS, Fallback);
- OS.flush();
setStr(Uncommon().COFFWeakExternFallbackName, Saver.save(FallbackName));
}
}
@@ -341,7 +340,6 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
if (Error Err = addModule(M))
return Err;
- COFFLinkerOptsOS.flush();
setStr(Hdr.COFFLinkerOpts, Saver.save(COFFLinkerOpts));
// We are about to fill in the header's range fields, so reserve space for it
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index ec5e08082b0ca..fbe083a663e0d 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -1257,7 +1257,6 @@ emitDebugSectionImpl(const DWARFYAML::Data &DI, StringRef Sec,
if (Error Err = EmitFunc(DebugInfoStream, DI))
return Err;
- DebugInfoStream.flush();
if (!Data.empty())
OutputBuffers[Sec] = MemoryBuffer::getMemBufferCopy(Data);
diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp
index 9052b4342c8c2..3e8e8cea65520 100644
--- a/llvm/lib/ObjectYAML/WasmEmitter.cpp
+++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp
@@ -77,7 +77,6 @@ class SubSectionWriter {
SubSectionWriter(raw_ostream &OS) : OS(OS), StringStream(OutString) {}
void done() {
- StringStream.flush();
encodeULEB128(OutString.size(), OS);
OS << OutString;
OutString.clear();
@@ -545,7 +544,6 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
Func.Body.writeAsBinary(StringStream);
// Write the section size followed by the content
- StringStream.flush();
encodeULEB128(OutString.size(), OS);
OS << OutString;
}
@@ -653,8 +651,6 @@ bool WasmWriter::writeWasm(raw_ostream &OS) {
if (HasError)
return false;
- StringStream.flush();
-
unsigned HeaderSecSizeEncodingLen =
Sec->HeaderSecSizeEncodingLen.value_or(5);
unsigned RequiredLen = getULEB128Size(OutString.size());
@@ -682,7 +678,6 @@ bool WasmWriter::writeWasm(raw_ostream &OS) {
std::string OutString;
raw_string_ostream StringStream(OutString);
writeRelocSection(StringStream, *Sec, SectionIndex++);
- StringStream.flush();
encodeULEB128(OutString.size(), OS);
OS << OutString;
diff --git a/llvm/lib/Remarks/YAMLRemarkParser.cpp b/llvm/lib/Remarks/YAMLRemarkParser.cpp
index baad378d72bd4..a8b1c0cc29ad6 100644
--- a/llvm/lib/Remarks/YAMLRemarkParser.cpp
+++ b/llvm/lib/Remarks/YAMLRemarkParser.cpp
@@ -31,7 +31,6 @@ static void handleDiagnostic(const SMDiagnostic &Diag, void *Ctx) {
Diag.print(/*ProgName=*/nullptr, OS, /*ShowColors*/ false,
/*ShowKindLabels*/ true);
OS << '\n';
- OS.flush();
}
YAMLParseError::YAMLParseError(StringRef Msg, SourceMgr &SM,
diff --git a/llvm/lib/Support/Chrono.cpp b/llvm/lib/Support/Chrono.cpp
index 07a5940ddeb21..13dd7cd49b372 100644
--- a/llvm/lib/Support/Chrono.cpp
+++ b/llvm/lib/Support/Chrono.cpp
@@ -101,7 +101,6 @@ static void format(const T &Fractional, struct tm <, raw_ostream &OS,
}
FStream << Style[I];
}
- FStream.flush();
char Buffer[256]; // Should be enough for anywhen.
size_t Len = strftime(Buffer, sizeof(Buffer), Format.c_str(), <);
OS << (Len ? Buffer : "BAD-DATE-FORMAT");
More information about the llvm-commits
mailing list