[llvm] eb11f57 - [llvm][tools] Strip unneeded uses of raw_string_ostream::str() (NFC)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 13 04:14:41 PDT 2024
Author: JOE1994
Date: 2024-09-13T07:12:15-04:00
New Revision: eb11f576a4ffe9cc77d2010b5449bd7780472e2d
URL: https://github.com/llvm/llvm-project/commit/eb11f576a4ffe9cc77d2010b5449bd7780472e2d
DIFF: https://github.com/llvm/llvm-project/commit/eb11f576a4ffe9cc77d2010b5449bd7780472e2d.diff
LOG: [llvm][tools] Strip unneeded uses of raw_string_ostream::str() (NFC)
Remove excess layer of indirection.
Added:
Modified:
llvm/tools/dsymutil/MachODebugMapParser.cpp
llvm/tools/llvm-dwarfdump/Statistics.cpp
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/tools/dsymutil/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp
index c390d0b874948c..4a06731946b97d 100644
--- a/llvm/tools/dsymutil/MachODebugMapParser.cpp
+++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp
@@ -383,7 +383,7 @@ MachODebugMapParser::parseOneBinary(const MachOObjectFile &MainBinary,
llvm::raw_string_ostream OS(Buffer);
OS << sys::TimePoint<std::chrono::seconds>(sys::toTimePoint(OSO.second));
Warning("skipping debug map object with duplicate name and timestamp: " +
- OS.str() + Twine(" ") + Twine(OSO.first));
+ Buffer + Twine(" ") + Twine(OSO.first));
}
// Build the debug map by iterating over the STABS again but ignore the
diff --git a/llvm/tools/llvm-dwarfdump/Statistics.cpp b/llvm/tools/llvm-dwarfdump/Statistics.cpp
index 8d6dd17ceae904..6f2919318a6d5d 100644
--- a/llvm/tools/llvm-dwarfdump/Statistics.cpp
+++ b/llvm/tools/llvm-dwarfdump/Statistics.cpp
@@ -241,7 +241,7 @@ static std::string constructDieID(DWARFDie Die,
// Prefix + Name is enough for local variables and parameters.
if (!Prefix.empty() && Prefix != "g")
- return ID.str();
+ return IDStr;
auto DeclFile = Die.findRecursively(dwarf::DW_AT_decl_file);
std::string File;
@@ -256,7 +256,7 @@ static std::string constructDieID(DWARFDie Die,
ID << ":" << (File.empty() ? "/" : File);
ID << ":"
<< dwarf::toUnsigned(Die.findRecursively(dwarf::DW_AT_decl_line), 0);
- return ID.str();
+ return IDStr;
}
/// Return the number of bytes in the overlap of ranges A and B.
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 97633c0fe5a37e..ea69809c290545 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -2322,7 +2322,7 @@ std::string ELFDumper<ELFT>::getDynamicEntry(uint64_t Type,
const char *ConvChar =
(opts::Output == opts::GNU) ? "0x%" PRIx64 : "0x%" PRIX64;
OS << format(ConvChar, V);
- return OS.str();
+ return Str;
};
auto FormatFlags = [](uint64_t V,
@@ -2330,7 +2330,7 @@ std::string ELFDumper<ELFT>::getDynamicEntry(uint64_t Type,
std::string Str;
raw_string_ostream OS(Str);
printFlags(V, Array, OS);
- return OS.str();
+ return Str;
};
// Handle custom printing of architecture specific tags
@@ -5346,7 +5346,7 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
switch (Type) {
default:
OS << format("<application-specific type 0x%x>", Type);
- return OS.str();
+ return str;
case GNU_PROPERTY_STACK_SIZE: {
OS << "stack size: ";
if (DataSize == sizeof(typename ELFT::uint))
@@ -5354,25 +5354,25 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
(uint64_t)(*(const typename ELFT::Addr *)Data.data()));
else
OS << format("<corrupt length: 0x%x>", DataSize);
- return OS.str();
+ return str;
}
case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
OS << "no copy on protected";
if (DataSize)
OS << format(" <corrupt length: 0x%x>", DataSize);
- return OS.str();
+ return str;
case GNU_PROPERTY_AARCH64_FEATURE_1_AND:
case GNU_PROPERTY_X86_FEATURE_1_AND:
OS << ((Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) ? "aarch64 feature: "
: "x86 feature: ");
if (DataSize != 4) {
OS << format("<corrupt length: 0x%x>", DataSize);
- return OS.str();
+ return str;
}
PrData = endian::read32<ELFT::Endianness>(Data.data());
if (PrData == 0) {
OS << "<None>";
- return OS.str();
+ return str;
}
if (Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_BTI, "BTI");
@@ -5384,22 +5384,22 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
}
if (PrData)
OS << format("<unknown flags: 0x%x>", PrData);
- return OS.str();
+ return str;
case GNU_PROPERTY_AARCH64_FEATURE_PAUTH:
printAArch64PAuthABICoreInfo<ELFT>(OS, DataSize, Data);
- return OS.str();
+ return str;
case GNU_PROPERTY_X86_FEATURE_2_NEEDED:
case GNU_PROPERTY_X86_FEATURE_2_USED:
OS << "x86 feature "
<< (Type == GNU_PROPERTY_X86_FEATURE_2_NEEDED ? "needed: " : "used: ");
if (DataSize != 4) {
OS << format("<corrupt length: 0x%x>", DataSize);
- return OS.str();
+ return str;
}
PrData = endian::read32<ELFT::Endianness>(Data.data());
if (PrData == 0) {
OS << "<None>";
- return OS.str();
+ return str;
}
DumpBit(GNU_PROPERTY_X86_FEATURE_2_X86, "x86");
DumpBit(GNU_PROPERTY_X86_FEATURE_2_X87, "x87");
@@ -5413,19 +5413,19 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
DumpBit(GNU_PROPERTY_X86_FEATURE_2_XSAVEC, "XSAVEC");
if (PrData)
OS << format("<unknown flags: 0x%x>", PrData);
- return OS.str();
+ return str;
case GNU_PROPERTY_X86_ISA_1_NEEDED:
case GNU_PROPERTY_X86_ISA_1_USED:
OS << "x86 ISA "
<< (Type == GNU_PROPERTY_X86_ISA_1_NEEDED ? "needed: " : "used: ");
if (DataSize != 4) {
OS << format("<corrupt length: 0x%x>", DataSize);
- return OS.str();
+ return str;
}
PrData = endian::read32<ELFT::Endianness>(Data.data());
if (PrData == 0) {
OS << "<None>";
- return OS.str();
+ return str;
}
DumpBit(GNU_PROPERTY_X86_ISA_1_BASELINE, "x86-64-baseline");
DumpBit(GNU_PROPERTY_X86_ISA_1_V2, "x86-64-v2");
@@ -5433,7 +5433,7 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
DumpBit(GNU_PROPERTY_X86_ISA_1_V4, "x86-64-v4");
if (PrData)
OS << format("<unknown flags: 0x%x>", PrData);
- return OS.str();
+ return str;
}
}
@@ -5453,7 +5453,7 @@ static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr) {
raw_string_ostream OS(str);
if (Arr.size() < PaddedSize) {
OS << format("<corrupt type (0x%x) datasz: 0x%x>", Type, DataSize);
- Properties.push_back(OS.str());
+ Properties.push_back(str);
break;
}
Properties.push_back(
@@ -5492,7 +5492,7 @@ template <typename ELFT> static GNUAbiTag getGNUAbiTag(ArrayRef<uint8_t> Desc) {
std::string str;
raw_string_ostream ABI(str);
ABI << Major << "." << Minor << "." << Patch;
- return {std::string(OSName), ABI.str(), /*IsValid=*/true};
+ return {std::string(OSName), str, /*IsValid=*/true};
}
static std::string getGNUBuildId(ArrayRef<uint8_t> Desc) {
@@ -5500,7 +5500,7 @@ static std::string getGNUBuildId(ArrayRef<uint8_t> Desc) {
raw_string_ostream OS(str);
for (uint8_t B : Desc)
OS << format_hex_no_prefix(B, 2);
- return OS.str();
+ return str;
}
static StringRef getDescAsStringRef(ArrayRef<uint8_t> Desc) {
@@ -5670,11 +5670,11 @@ getFreeBSDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc, bool IsCore) {
std::string FlagsStr;
raw_string_ostream OS(FlagsStr);
printFlags(Value, ArrayRef(FreeBSDFeatureCtlFlags), OS);
- if (OS.str().empty())
+ if (FlagsStr.empty())
OS << "0x" << utohexstr(Value);
else
OS << "(0x" << utohexstr(Value) << ")";
- return FreeBSDNote{"Feature flags", OS.str()};
+ return FreeBSDNote{"Feature flags", FlagsStr};
}
default:
return std::nullopt;
@@ -5822,7 +5822,7 @@ static AMDGPUNote getAMDGPUNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
return {"", ""};
}
MsgPackDoc.toYAML(StrOS);
- return {"AMDGPU Metadata", StrOS.str()};
+ return {"AMDGPU Metadata", MetadataString};
}
}
}
More information about the llvm-commits
mailing list