[llvm] [DebugInfo] Convert format() to formatv() in DWARFVerifier (PR #179194)

Konrad Kleine via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 2 06:05:11 PST 2026


https://github.com/kwk updated https://github.com/llvm/llvm-project/pull/179194

>From 87a8828dd2258fe38376cd7162f04b90af0e9f57 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Thu, 29 Jan 2026 15:50:03 +0000
Subject: [PATCH 1/6] [DebugInfo] Convert format() to formatv() in
 DWARFVerifier

Replace all of calls of `format()` with `formatv()` in `DWARFVerifier.cpp`.

See `llvm/include/llvm/Support/FormatProviders.h` for the grammar. e.g.
`x+` to print the `0x` prefix or `x-` to not print it.

Relates to #35980
---
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 78 ++++++++++------------
 1 file changed, 37 insertions(+), 41 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 3a92140ede9d0..5ae41e42962ae 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -182,8 +182,8 @@ bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
     bool HeaderShown = false;
     auto ShowHeaderOnce = [&]() {
       if (!HeaderShown) {
-        error() << format("Units[%d] - start offset: 0x%08" PRIx64 " \n",
-                          UnitIndex, OffsetStart);
+        error() << formatv("Units[{0}] - start offset: {1:x+8}\n", UnitIndex,
+                           OffsetStart);
         HeaderShown = true;
       }
     };
@@ -957,10 +957,9 @@ unsigned DWARFVerifier::verifyDebugInfoForm(const DWARFDie &Die,
       if (CUOffset >= CUSize) {
         ++NumErrors;
         ErrorCategory.Report("Invalid CU offset", [&]() {
-          error() << FormEncodingString(Form) << " CU offset "
-                  << format("0x%08" PRIx64, CUOffset)
-                  << " is invalid (must be less than CU size of "
-                  << format("0x%08" PRIx64, CUSize) << "):\n";
+          error() << formatv("{0} CU offset {1:x+8} is invalid (must be less "
+                             "than CU size of {2:x+8}):\n",
+                             FormEncodingString(Form), CUOffset, CUSize);
           Die.dump(OS, 0, DumpOpts);
           dump(Die) << '\n';
         });
@@ -1032,8 +1031,9 @@ unsigned DWARFVerifier::verifyDebugInfoReferences(
       continue;
     ++NumErrors;
     ErrorCategory.Report("Invalid DIE reference", [&]() {
-      error() << "invalid DIE reference " << format("0x%08" PRIx64, Pair.first)
-              << ". Offset is in between DIEs:\n";
+      error() << formatv(
+          "invalid DIE reference {0:x+8}. Offset is in between DIEs:\n",
+          Pair.first);
       for (auto Offset : Pair.second)
         dump(GetDIEForOffset(Offset)) << '\n';
       OS << "\n";
@@ -1058,8 +1058,9 @@ void DWARFVerifier::verifyDebugLineStmtOffsets() {
       if (!LineTable) {
         ++NumDebugLineErrors;
         ErrorCategory.Report("Unparsable .debug_line entry", [&]() {
-          error() << ".debug_line[" << format("0x%08" PRIx64, LineTableOffset)
-                  << "] was not able to be parsed for CU:\n";
+          error() << formatv(
+              ".debug_line[{0:x+8}] was not able to be parsed for CU:\n",
+              LineTableOffset);
           dump(Die) << '\n';
         });
         continue;
@@ -1076,10 +1077,9 @@ void DWARFVerifier::verifyDebugLineStmtOffsets() {
       ++NumDebugLineErrors;
       const auto &OldDie = Iter->second;
       ErrorCategory.Report("Identical DW_AT_stmt_list section offset", [&]() {
-        error() << "two compile unit DIEs, "
-                << format("0x%08" PRIx64, OldDie.getOffset()) << " and "
-                << format("0x%08" PRIx64, Die.getOffset())
-                << ", have the same DW_AT_stmt_list section offset:\n";
+        error() << formatv("two compile unit DIEs, {0:x+8} and {1:x+8}, have "
+                           "the same DW_AT_stmt_list section offset:\n",
+                           OldDie.getOffset(), Die.getOffset());
         dump(OldDie);
         dump(Die) << '\n';
       });
@@ -1110,10 +1110,9 @@ void DWARFVerifier::verifyDebugLineRows() {
         ErrorCategory.Report(
             "Invalid index in .debug_line->prologue.file_names->dir_idx",
             [&]() {
-              error() << ".debug_line["
-                      << format("0x%08" PRIx64,
-                                *toSectionOffset(Die.find(DW_AT_stmt_list)))
-                      << "].prologue.file_names[" << FileIndex
+              error() << formatv(".debug_line[{0:x+8}].prologue.file_names[{1}",
+                                 *toSectionOffset(Die.find(DW_AT_stmt_list)),
+                                 FileIndex)
                       << "].dir_idx contains an invalid index: "
                       << FileName.DirIdx << "\n";
             });
@@ -1128,10 +1127,9 @@ void DWARFVerifier::verifyDebugLineRows() {
       (void)HasFullPath;
       auto [It, Inserted] = FullPathMap.try_emplace(FullPath, FileIndex);
       if (!Inserted && It->second != FileIndex && DumpOpts.Verbose) {
-        warn() << ".debug_line["
-               << format("0x%08" PRIx64,
-                         *toSectionOffset(Die.find(DW_AT_stmt_list)))
-               << "].prologue.file_names[" << FileIndex
+        warn() << formatv(".debug_line[{0:x+8}].prologue.file_names[{1}",
+                          *toSectionOffset(Die.find(DW_AT_stmt_list)),
+                          FileIndex)
                << "] is a duplicate of file_names[" << It->second << "]\n";
       }
 
@@ -1152,10 +1150,9 @@ void DWARFVerifier::verifyDebugLineRows() {
         ++NumDebugLineErrors;
         ErrorCategory.Report(
             "decreasing address between debug_line rows", [&]() {
-              error() << ".debug_line["
-                      << format("0x%08" PRIx64,
-                                *toSectionOffset(Die.find(DW_AT_stmt_list)))
-                      << "] row[" << RowIndex
+              error() << formatv(".debug_line[{0:x+8}] row[{1}",
+                                 *toSectionOffset(Die.find(DW_AT_stmt_list)),
+                                 RowIndex)
                       << "] decreases in address from previous row:\n";
 
               DWARFDebugLine::Row::dumpTableHeader(OS, 0);
@@ -1169,10 +1166,10 @@ void DWARFVerifier::verifyDebugLineRows() {
       if (!LineTable->hasFileAtIndex(Row.File)) {
         ++NumDebugLineErrors;
         ErrorCategory.Report("Invalid file index in debug_line", [&]() {
-          error() << ".debug_line["
-                  << format("0x%08" PRIx64,
-                            *toSectionOffset(Die.find(DW_AT_stmt_list)))
-                  << "][" << RowIndex << "] has invalid file index " << Row.File
+          error() << formatv(
+                         ".debug_line[{0:x+8}][{1}] has invalid file index {2}",
+                         *toSectionOffset(Die.find(DW_AT_stmt_list)), RowIndex,
+                         Row.File)
                   << " (valid values are [" << MinFileIndex << ','
                   << LineTable->Prologue.FileNames.size()
                   << (isDWARF5 ? ")" : "]") << "):\n";
@@ -1247,8 +1244,8 @@ void DWARFVerifier::verifyAppleAccelTable(const DWARFSection *AccelSection,
     uint32_t HashIdx = AccelSectionData.getU32(&BucketsOffset);
     if (HashIdx >= NumHashes && HashIdx != UINT32_MAX) {
       ErrorCategory.Report("Invalid hash index", [&]() {
-        error() << format("Bucket[%d] has invalid hash index: %u.\n", BucketIdx,
-                          HashIdx);
+        error() << formatv("Bucket[{0}] has invalid hash index: {1}.\n",
+                           BucketIdx, HashIdx);
       });
     }
   }
@@ -1274,9 +1271,8 @@ void DWARFVerifier::verifyAppleAccelTable(const DWARFSection *AccelSection,
     if (!AccelSectionData.isValidOffsetForDataOfSize(HashDataOffset,
                                                      sizeof(uint64_t))) {
       ErrorCategory.Report("Invalid HashData offset", [&]() {
-        error() << format("Hash[%d] has invalid HashData offset: "
-                          "0x%08" PRIx64 ".\n",
-                          HashIdx, HashDataOffset);
+        error() << formatv("Hash[{0}] has invalid HashData offset: {1:x+8}.\n",
+                           HashIdx, HashDataOffset);
       });
     }
 
@@ -1301,12 +1297,12 @@ void DWARFVerifier::verifyAppleAccelTable(const DWARFSection *AccelSection,
             Name = "<NULL>";
 
           ErrorCategory.Report("Invalid DIE offset", [&]() {
-            error() << format(
-                "%s Bucket[%d] Hash[%d] = 0x%08x "
-                "Str[%u] = 0x%08" PRIx64 " DIE[%d] = 0x%08" PRIx64 " "
-                "is not a valid DIE offset for \"%s\".\n",
-                SectionName, BucketIdx, HashIdx, Hash, StringCount, StrpOffset,
-                HashDataIdx, Offset, Name);
+            error() << formatv("{0} Bucket[{1}] Hash[{2}] = {3:x+8} "
+                               "Str[{4}] = {5:x+8} DIE[{6}] = {7:x+8} "
+                               "is not a valid DIE offset for \"{8}\".\n",
+                               SectionName, BucketIdx, HashIdx, Hash,
+                               StringCount, StrpOffset, HashDataIdx, Offset,
+                               Name);
           });
           continue;
         }

>From a4b9eee02816ddce9a2c2228c15b2b9f4f675be6 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Mon, 2 Feb 2026 11:08:36 +0000
Subject: [PATCH 2/6] Include rest of string in formatv

---
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 5ae41e42962ae..d6a34373a8269 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -1110,11 +1110,10 @@ void DWARFVerifier::verifyDebugLineRows() {
         ErrorCategory.Report(
             "Invalid index in .debug_line->prologue.file_names->dir_idx",
             [&]() {
-              error() << formatv(".debug_line[{0:x+8}].prologue.file_names[{1}",
+              error() << formatv(".debug_line[{0:x+8}].prologue.file_names[{1}]"
+                                 ".dir_idx contains an invalid index: {2}\n",
                                  *toSectionOffset(Die.find(DW_AT_stmt_list)),
-                                 FileIndex)
-                      << "].dir_idx contains an invalid index: "
-                      << FileName.DirIdx << "\n";
+                                 FileIndex, FileName.DirIdx);
             });
       }
 
@@ -1127,10 +1126,10 @@ void DWARFVerifier::verifyDebugLineRows() {
       (void)HasFullPath;
       auto [It, Inserted] = FullPathMap.try_emplace(FullPath, FileIndex);
       if (!Inserted && It->second != FileIndex && DumpOpts.Verbose) {
-        warn() << formatv(".debug_line[{0:x+8}].prologue.file_names[{1}",
+        warn() << formatv(".debug_line[{0:x+8}].prologue.file_names[{1}] is a "
+                          "duplicate of file_names[{2}]\n",
                           *toSectionOffset(Die.find(DW_AT_stmt_list)),
-                          FileIndex)
-               << "] is a duplicate of file_names[" << It->second << "]\n";
+                          FileIndex, It->second);
       }
 
       FileIndex++;
@@ -1150,10 +1149,10 @@ void DWARFVerifier::verifyDebugLineRows() {
         ++NumDebugLineErrors;
         ErrorCategory.Report(
             "decreasing address between debug_line rows", [&]() {
-              error() << formatv(".debug_line[{0:x+8}] row[{1}",
+              error() << formatv(".debug_line[{0:x+8}] row[{1}] decreases in "
+                                 "address from previous row:\n",
                                  *toSectionOffset(Die.find(DW_AT_stmt_list)),
-                                 RowIndex)
-                      << "] decreases in address from previous row:\n";
+                                 RowIndex);
 
               DWARFDebugLine::Row::dumpTableHeader(OS, 0);
               if (RowIndex > 0)

>From d5fb3ddb3f7323184ca19c8bf0e1584a28a07bb1 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Mon, 2 Feb 2026 11:29:02 +0000
Subject: [PATCH 3/6] Additional formatv usage

---
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 30 ++++++++++++----------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index d6a34373a8269..e2b97f7b02888 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -712,11 +712,12 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
       if (U->isDWOUnit() && RangeSection.Data.empty())
         break;
       if (*SectionOffset >= RangeSection.Data.size())
-        ReportError("DW_AT_ranges offset out of bounds",
-                    "DW_AT_ranges offset is beyond " +
-                        StringRef(DwarfVersion < 5 ? ".debug_ranges"
-                                                   : ".debug_rnglists") +
-                        " bounds: " + llvm::formatv("{0:x8}", *SectionOffset));
+        ReportError(
+            "DW_AT_ranges offset out of bounds",
+            llvm::formatv("DW_AT_ranges offset is beyond {0} bounds: {1:x8}",
+                          StringRef(DwarfVersion < 5 ? ".debug_ranges"
+                                                     : ".debug_rnglists"),
+                          *SectionOffset));
       break;
     }
     ReportError("Invalid DW_AT_ranges encoding",
@@ -726,9 +727,11 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
     // Make sure the offset in the DW_AT_stmt_list attribute is valid.
     if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) {
       if (*SectionOffset >= U->getLineSection().Data.size())
-        ReportError("DW_AT_stmt_list offset out of bounds",
-                    "DW_AT_stmt_list offset is beyond .debug_line bounds: " +
-                        llvm::formatv("{0:x8}", *SectionOffset));
+        ReportError(
+            "DW_AT_stmt_list offset out of bounds",
+            llvm::formatv(
+                "DW_AT_stmt_list offset is beyond .debug_line bounds: {0:x8}",
+                *SectionOffset));
       break;
     }
     ReportError("Invalid DW_AT_stmt_list encoding",
@@ -811,12 +814,11 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
           if (std::optional<uint64_t> LastFileIdx =
                   LT->getLastValidFileIndex()) {
             ReportError("Invalid file index in DW_AT_decl_file",
-                        "DIE has " + AttributeString(Attr) +
-                            " with an invalid file index " +
-                            llvm::formatv("{0}", *FileIdx) +
-                            " (valid values are [" +
-                            (IsZeroIndexed ? "0-" : "1-") +
-                            llvm::formatv("{0}", *LastFileIdx) + "])");
+                        llvm::formatv("DIE has {0} with an invalid file index "
+                                      "{1} (valid values are [{2}-{3}])",
+                                      AttributeString(Attr), *FileIdx,
+                                      (IsZeroIndexed ? "0" : "1"),
+                                      *LastFileIdx));
           } else {
             ReportError("Invalid file index in DW_AT_decl_file",
                         "DIE has " + AttributeString(Attr) +

>From 760d2c7b9d982b1304d90234566e622b4bb1e6a3 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Mon, 2 Feb 2026 12:44:08 +0000
Subject: [PATCH 4/6] More formatting

---
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 62 ++++++++++------------
 1 file changed, 29 insertions(+), 33 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index e2b97f7b02888..6a8502e56d45a 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -820,25 +820,24 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
                                       (IsZeroIndexed ? "0" : "1"),
                                       *LastFileIdx));
           } else {
-            ReportError("Invalid file index in DW_AT_decl_file",
-                        "DIE has " + AttributeString(Attr) +
-                            " with an invalid file index " +
-                            llvm::formatv("{0}", *FileIdx) +
-                            " (the file table in the prologue is empty)");
+            ReportError(
+                "Invalid file index in DW_AT_decl_file",
+                llvm::formatv("DIE has {0} with an invalid file index {1} (the "
+                              "file table in the prologue is empty)",
+                              AttributeString(Attr), *FileIdx));
           }
         }
       } else {
         ReportError(
             "File index in DW_AT_decl_file reference CU with no line table",
-            "DIE has " + AttributeString(Attr) +
-                " that references a file with index " +
-                llvm::formatv("{0}", *FileIdx) +
-                " and the compile unit has no line table");
+            llvm::formatv("DIE has {0} that references a file with index {1} "
+                          "and the compile unit has no line table",
+                          AttributeString(Attr), *FileIdx));
       }
     } else {
       ReportError("Invalid encoding in DW_AT_decl_file",
-                  "DIE has " + AttributeString(Attr) +
-                      " with invalid encoding");
+                  llvm::formatv("DIE has {0} with invalid encoding",
+                                AttributeString(Attr)));
     }
     break;
   }
@@ -909,11 +908,9 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
     // Check if the offset is within the bounds of this specific line table
     if (*SectionOffset < SequencesStart || *SectionOffset >= LineTableEnd) {
       ReportError("DW_AT_LLVM_stmt_sequence offset out of line table bounds",
-                  "DW_AT_LLVM_stmt_sequence offset " +
-                      llvm::formatv("{0:x8}", *SectionOffset) +
-                      " is not within the line table bounds [" +
-                      llvm::formatv("{0:x8}", SequencesStart) + ", " +
-                      llvm::formatv("{0:x8}", LineTableEnd) + ")");
+                  llvm::formatv("DW_AT_LLVM_stmt_sequence offset {0:x8} is not "
+                                "within the line table bounds [{1:x8}, {2:x8})",
+                                *SectionOffset, SequencesStart, LineTableEnd));
       break;
     }
 
@@ -926,9 +923,9 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
     if (It == LineTable->Sequences.end())
       ReportError(
           "Invalid DW_AT_LLVM_stmt_sequence offset",
-          "DW_AT_LLVM_stmt_sequence offset " +
-              llvm::formatv("{0:x8}", *SectionOffset) +
-              " does not point to a valid sequence offset in the line table");
+          llvm::formatv("DW_AT_LLVM_stmt_sequence offset {0:x8} does not point "
+                        "to a valid sequence offset in the line table",
+                        *SectionOffset));
     break;
   }
   default:
@@ -1167,13 +1164,12 @@ void DWARFVerifier::verifyDebugLineRows() {
       if (!LineTable->hasFileAtIndex(Row.File)) {
         ++NumDebugLineErrors;
         ErrorCategory.Report("Invalid file index in debug_line", [&]() {
-          error() << formatv(
-                         ".debug_line[{0:x+8}][{1}] has invalid file index {2}",
-                         *toSectionOffset(Die.find(DW_AT_stmt_list)), RowIndex,
-                         Row.File)
-                  << " (valid values are [" << MinFileIndex << ','
-                  << LineTable->Prologue.FileNames.size()
-                  << (isDWARF5 ? ")" : "]") << "):\n";
+          error() << formatv(".debug_line[{0:x+8}][{1}] has invalid file index "
+                             "{2}  (valid values are [{3},{4}:\n",
+                             *toSectionOffset(Die.find(DW_AT_stmt_list)),
+                             RowIndex, Row.File, MinFileIndex,
+                             LineTable->Prologue.FileNames.size(),
+                             (isDWARF5 ? ")" : "]"));
           DWARFDebugLine::Row::dumpTableHeader(OS, 0);
           Row.dump(OS);
           OS << '\n';
@@ -1309,10 +1305,10 @@ void DWARFVerifier::verifyAppleAccelTable(const DWARFSection *AccelSection,
         }
         if ((Tag != dwarf::DW_TAG_null) && (Die.getTag() != Tag)) {
           ErrorCategory.Report("Mismatched Tag in accellerator table", [&]() {
-            error() << "Tag " << dwarf::TagString(Tag)
-                    << " in accelerator table does not match Tag "
-                    << dwarf::TagString(Die.getTag()) << " of DIE["
-                    << HashDataIdx << "].\n";
+            error() << formatv("Tag {0} in accelerator table does not match "
+                               "Tag {1} of DIE[{2}].\n",
+                               dwarf::TagString(Tag),
+                               dwarf::TagString(Die.getTag()), HashDataIdx);
           });
         }
       }
@@ -2369,9 +2365,9 @@ void DWARFVerifier::summarize() {
     raw_fd_ostream JsonStream(DumpOpts.JsonErrSummaryFile, EC,
                               sys::fs::OF_Text);
     if (EC) {
-      error() << "unable to open json summary file '"
-              << DumpOpts.JsonErrSummaryFile
-              << "' for writing: " << EC.message() << '\n';
+      error() << formatv(
+          "unable to open json summary file {0} for writing: {1}\n",
+          DumpOpts.JsonErrSummaryFile, EC.message());
       return;
     }
 

>From 85292a8e55e5a6cc997c6c24aad2f90e366ba739 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Mon, 2 Feb 2026 13:18:43 +0000
Subject: [PATCH 5/6] More formatting

---
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 54 +++++++++++-----------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 6a8502e56d45a..519f9778850bf 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -272,8 +272,8 @@ unsigned DWARFVerifier::verifyUnitContents(DWARFUnit &Unit,
     if (Die.hasChildren()) {
       if (Die.getFirstChild().isValid() &&
           Die.getFirstChild().getTag() == DW_TAG_null) {
-        warn() << dwarf::TagString(Die.getTag())
-               << " has DW_CHILDREN_yes but DIE has no children: ";
+        warn() << formatv("{0} has DW_CHILDREN_yes but DIE has no children: ",
+                          dwarf::TagString(Die.getTag()));
         Die.dump(OS);
       }
     }
@@ -292,8 +292,8 @@ unsigned DWARFVerifier::verifyUnitContents(DWARFUnit &Unit,
 
   if (!dwarf::isUnitType(Die.getTag())) {
     ErrorCategory.Report("Compilation unit root DIE is not a unit DIE", [&]() {
-      error() << "Compilation unit root DIE is not a unit DIE: "
-              << dwarf::TagString(Die.getTag()) << ".\n";
+      error() << formatv("Compilation unit root DIE is not a unit DIE: {0}.\n",
+                         dwarf::TagString(Die.getTag()));
     });
     NumUnitErrors++;
   }
@@ -301,9 +301,9 @@ unsigned DWARFVerifier::verifyUnitContents(DWARFUnit &Unit,
   uint8_t UnitType = Unit.getUnitType();
   if (!DWARFUnit::isMatchingUnitTypeAndTag(UnitType, Die.getTag())) {
     ErrorCategory.Report("Mismatched unit type", [&]() {
-      error() << "Compilation unit type (" << dwarf::UnitTypeString(UnitType)
-              << ") and root DIE (" << dwarf::TagString(Die.getTag())
-              << ") do not match.\n";
+      error() << formatv(
+          "Compilation unit type ({0}) and root DIE ({1}) do not match.\n",
+          dwarf::UnitTypeString(UnitType), dwarf::TagString(Die.getTag()));
     });
     NumUnitErrors++;
   }
@@ -389,8 +389,9 @@ unsigned DWARFVerifier::verifyAbbrevSection(const DWARFDebugAbbrev *Abbrev) {
       if (!Result.second) {
         ErrorCategory.Report(
             "Abbreviation declartion contains multiple attributes", [&]() {
-              error() << "Abbreviation declaration contains multiple "
-                      << AttributeString(Attribute.Attr) << " attributes.\n";
+              error() << formatv("Abbreviation declaration contains multiple "
+                                 "{0} attributes.\n",
+                                 AttributeString(Attribute.Attr));
               AbbrDecl.dump(OS);
             });
         ++NumErrors;
@@ -418,10 +419,11 @@ unsigned DWARFVerifier::verifyUnits(const DWARFUnitVector &Units) {
   ReferenceMap CrossUnitReferences;
 
   unsigned Index = 1;
+
   for (const auto &Unit : Units) {
-    OS << "Verifying unit: " << Index << " / " << Units.getNumUnits();
+    OS << formatv("Verifying unit: {0} / {1}\n", Index, Units.getNumUnits());
     if (const char* Name = Unit->getUnitDIE(true).getShortName())
-      OS << ", \"" << Name << '\"';
+      OS << formatv(", \"{0}\"", Name);
     OS << '\n';
     OS.flush();
     ReferenceMap UnitLocalReferences;
@@ -600,7 +602,7 @@ unsigned DWARFVerifier::verifyDieRanges(const DWARFDie &Die,
       if (!Range.valid()) {
         ++NumErrors;
         ErrorCategory.Report("Invalid address range", [&]() {
-          error() << "Invalid address range " << Range << "\n";
+          error() << formatv("Invalid address range {0}\n", Range);
           DumpDieAfterError = true;
         });
         continue;
@@ -615,8 +617,9 @@ unsigned DWARFVerifier::verifyDieRanges(const DWARFDie &Die,
       if (auto PrevRange = RI.insert(Range)) {
         ++NumErrors;
         ErrorCategory.Report("DIE has overlapping DW_AT_ranges", [&]() {
-          error() << "DIE has overlapping ranges in DW_AT_ranges attribute: "
-                  << *PrevRange << " and " << Range << '\n';
+          error() << formatv("DIE has overlapping ranges in DW_AT_ranges "
+                             "attribute: {0} and {1}\n",
+                             *PrevRange, Range);
           DumpDieAfterError = true;
         });
       }
@@ -693,7 +696,7 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
   auto ReportError = [&](StringRef category, const Twine &TitleMsg) {
     ++NumErrors;
     ErrorCategory.Report(category, [&]() {
-      error() << TitleMsg << '\n';
+      error() << formatv("{0}\n", TitleMsg);
       dump(Die) << '\n';
     });
   };
@@ -785,11 +788,10 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
       if (DieTag == DW_TAG_GNU_call_site && RefTag == DW_TAG_subprogram)
         break;
       ReportError("Incompatible DW_AT_abstract_origin tag reference",
-                  "DIE with tag " + TagString(DieTag) + " has " +
-                      AttributeString(Attr) +
-                      " that points to DIE with "
-                      "incompatible tag " +
-                      TagString(RefTag));
+                  formatv("DIE with tag {0} has {1} that points to DIE with "
+                          "incompatible tag {2}",
+                          TagString(DieTag), AttributeString(Attr),
+                          TagString(RefTag)));
     }
     break;
   }
@@ -797,8 +799,8 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
     DWARFDie TypeDie = Die.getAttributeValueAsReferencedDie(DW_AT_type);
     if (TypeDie && !isType(TypeDie.getTag())) {
       ReportError("Incompatible DW_AT_type attribute tag",
-                  "DIE has " + AttributeString(Attr) +
-                      " with incompatible tag " + TagString(TypeDie.getTag()));
+                  formatv("DIE has {0} with incompatible tag {1}",
+                          AttributeString(Attr), TagString(TypeDie.getTag())));
     }
     break;
   }
@@ -847,7 +849,7 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
       ReportError(
           Attr == DW_AT_call_line ? "Invalid file index in DW_AT_decl_line"
                                   : "Invalid file index in DW_AT_call_line",
-          "DIE has " + AttributeString(Attr) + " with invalid encoding");
+          formatv("DIE has {0} with invalid encoding", AttributeString(Attr)));
     }
     break;
   }
@@ -1003,7 +1005,7 @@ unsigned DWARFVerifier::verifyDebugInfoForm(const DWARFDie &Die,
       ++NumErrors;
       std::string ErrMsg = toString(std::move(E));
       ErrorCategory.Report("Invalid DW_FORM attribute", [&]() {
-        error() << ErrMsg << ":\n";
+        error() << formatv("{0}:\n", ErrMsg);
         dump(Die) << '\n';
       });
     }
@@ -2310,7 +2312,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
   if (Error E = C.takeError()) {
     std::string Msg = toString(std::move(E));
     ErrorCategory.Report("String offset error", [&]() {
-      error() << SectionName << ": " << Msg << '\n';
+      error() << formatv("{0}: {1}\n", SectionName, Msg);
       return false;
     });
   }
@@ -2357,7 +2359,7 @@ void DWARFVerifier::summarize() {
   if (DumpOpts.ShowAggregateErrors && ErrorCategory.GetNumCategories()) {
     error() << "Aggregated error counts:\n";
     ErrorCategory.EnumerateResults([&](StringRef s, unsigned count) {
-      error() << s << " occurred " << count << " time(s).\n";
+      error() << formatv("{0} occurred {1} time(s).\n", s, count);
     });
   }
   if (!DumpOpts.JsonErrSummaryFile.empty()) {

>From f64a6c2c203eea8608b4a1cd0c7d1d8219c0fe26 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Mon, 2 Feb 2026 13:52:51 +0000
Subject: [PATCH 6/6] Fixup

---
 llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 519f9778850bf..05191f68e0ddd 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -421,7 +421,7 @@ unsigned DWARFVerifier::verifyUnits(const DWARFUnitVector &Units) {
   unsigned Index = 1;
 
   for (const auto &Unit : Units) {
-    OS << formatv("Verifying unit: {0} / {1}\n", Index, Units.getNumUnits());
+    OS << formatv("Verifying unit: {0} / {1}", Index, Units.getNumUnits());
     if (const char* Name = Unit->getUnitDIE(true).getShortName())
       OS << formatv(", \"{0}\"", Name);
     OS << '\n';
@@ -1167,7 +1167,7 @@ void DWARFVerifier::verifyDebugLineRows() {
         ++NumDebugLineErrors;
         ErrorCategory.Report("Invalid file index in debug_line", [&]() {
           error() << formatv(".debug_line[{0:x+8}][{1}] has invalid file index "
-                             "{2}  (valid values are [{3},{4}:\n",
+                             "{2}  (valid values are [{3},{4}{5}):\n",
                              *toSectionOffset(Die.find(DW_AT_stmt_list)),
                              RowIndex, Row.File, MinFileIndex,
                              LineTable->Prologue.FileNames.size(),



More information about the llvm-commits mailing list