[llvm] [llvm][DebugInfo][DWARF] Use formatv() instead of format() (PR #191308)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 09:06:38 PDT 2026
================
@@ -101,30 +103,31 @@ constexpr uint64_t getCIEId(bool IsDWARF64, bool IsEH) {
void CIE::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
// A CIE with a zero length is a terminator entry in the .eh_frame section.
if (DumpOpts.IsEH && Length == 0) {
- OS << format("%08" PRIx64, Offset) << " ZERO terminator\n";
+ OS << formatv("{0:x-8}", Offset) << " ZERO terminator\n";
return;
}
- OS << format("%08" PRIx64, Offset)
- << format(" %0*" PRIx64, IsDWARF64 ? 16 : 8, Length)
- << format(" %0*" PRIx64, IsDWARF64 && !DumpOpts.IsEH ? 16 : 8,
- getCIEId(IsDWARF64, DumpOpts.IsEH))
+ OS << formatv("{0:x-8}", Offset)
+ << formatv(" {0:x-}",
+ fmt_align(Length, AlignStyle::Right, IsDWARF64 ? 16 : 8, '0'))
+ << formatv(" {0:x-}",
+ fmt_align(getCIEId(IsDWARF64, DumpOpts.IsEH), AlignStyle::Right,
+ IsDWARF64 && !DumpOpts.IsEH ? 16 : 8, '0'))
<< " CIE\n"
<< " Format: " << FormatString(IsDWARF64) << "\n";
if (DumpOpts.IsEH && Version != 1)
OS << "WARNING: unsupported CIE version\n";
- OS << format(" Version: %d\n", Version)
+ OS << formatv(" Version: {0}\n", Version)
<< " Augmentation: \"" << Augmentation << "\"\n";
if (Version >= 4) {
- OS << format(" Address size: %u\n", (uint32_t)AddressSize);
- OS << format(" Segment desc size: %u\n",
- (uint32_t)SegmentDescriptorSize);
+ OS << formatv(" Address size: {0}\n", AddressSize);
+ OS << formatv(" Segment desc size: {0}\n", SegmentDescriptorSize);
}
- OS << format(" Code alignment factor: %u\n", (uint32_t)CodeAlignmentFactor);
- OS << format(" Data alignment factor: %d\n", (int32_t)DataAlignmentFactor);
- OS << format(" Return address column: %d\n", (int32_t)ReturnAddressRegister);
----------------
DavidSpickett wrote:
I'm not so sure about these ones. These members are:
```
const uint64_t CodeAlignmentFactor;
const int64_t DataAlignmentFactor;
const uint64_t ReturnAddressRegister;
```
And I presume the casts are known to be safe because the values will never exceed safe limits.
So if we don't want to get down a rabbit hole fixing the type, I suggest that for things like this, we keep the explicit casts that were there.
You could argue that if we know the ranges are fine, then as along as the casts don't change signedness then it's ok to remove them.
Except that ReturnAddressRegister is unsigned 64 but is cast to int32. Which itself looks like a mistake but again for the purposes of this PR, I would stick to what was being done previously.
https://github.com/llvm/llvm-project/pull/191308
More information about the llvm-commits
mailing list