[llvm] [llvm][DebugInfo] Use formatv in DWARFExpressionPrinter (PR #191993)

Konrad Kleine via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 08:35:37 PDT 2026


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

>From e0e70af781120af3139df34e6aa945d503f3b8e7 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Mon, 13 Apr 2026 20:18:43 +0000
Subject: [PATCH 1/2] [llvm][DebugInfo] formatv in DWARFExpressionPrinter

This relates to #35980.
---
 .../DWARF/DWARFExpressionPrinter.cpp          | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp
index 5a3c1dd057193..f5e692deeb782 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp
@@ -29,19 +29,19 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
                                    unsigned Operand) {
   assert(Operand < Operands.size() && "operand out of bounds");
   if (!U) {
-    OS << format(" <base_type ref: 0x%" PRIx64 ">", Operands[Operand]);
+    OS << formatv(" <base_type ref: {0:x}>", Operands[Operand]);
     return;
   }
   auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
   if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
     OS << " (";
     if (DumpOpts.Verbose)
-      OS << format("0x%08" PRIx64 " -> ", Operands[Operand]);
-    OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]);
+      OS << formatv("{0:x8} -> ", Operands[Operand]);
+    OS << formatv("{0:x8})", U->getOffset() + Operands[Operand]);
     if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
       OS << " \"" << *Name << "\"";
   } else {
-    OS << format(" <invalid base_type ref: 0x%" PRIx64 ">", Operands[Operand]);
+    OS << formatv(" <invalid base_type ref: {0:x}>", Operands[Operand]);
   }
 }
 
@@ -142,7 +142,7 @@ static bool printOp(const DWARFExpression::Operation *Op, raw_ostream &OS,
         case 2:
         case 3: // global as uint32
         case 4:
-          OS << format(" 0x%" PRIx64, Op->getRawOperand(Operand));
+          OS << formatv(" {0:x}", Op->getRawOperand(Operand));
           break;
         default:
           assert(false);
@@ -150,14 +150,14 @@ static bool printOp(const DWARFExpression::Operation *Op, raw_ostream &OS,
       } else if (Size == DWARFExpression::Operation::SizeBlock) {
         uint64_t Offset = Op->getRawOperand(Operand);
         for (unsigned i = 0; i < Op->getRawOperand(Operand - 1); ++i)
-          OS << format(" 0x%02x",
-                       static_cast<uint8_t>(Expr->getData()[Offset++]));
+          OS << formatv(" {0:x2}",
+                        static_cast<uint8_t>(Expr->getData()[Offset++]));
       } else {
         if (Signed)
           OS << formatv(" {0:+d}", (int64_t)Op->getRawOperand(Operand));
         else if (Op->getCode() != DW_OP_entry_value &&
                  Op->getCode() != DW_OP_GNU_entry_value)
-          OS << format(" 0x%" PRIx64, Op->getRawOperand(Operand));
+          OS << formatv(" {0:x}", Op->getRawOperand(Operand));
       }
     }
   }
@@ -176,7 +176,8 @@ void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS,
     if (!printOp(&Op, OS, DumpOpts, E, U) && !DumpOpts.PrintRegisterOnly) {
       uint64_t FailOffset = Op.getEndOffset();
       while (FailOffset < E->getData().size())
-        OS << format(" %02x", static_cast<uint8_t>(E->getData()[FailOffset++]));
+        OS << formatv(" {0:x-2}",
+                      static_cast<uint8_t>(E->getData()[FailOffset++]));
       return;
     }
     if (!DumpOpts.PrintRegisterOnly) {

>From 829806f302d217305933ad07e121dfb08dac96a8 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Wed, 15 Apr 2026 15:35:06 +0000
Subject: [PATCH 2/2] Get rid of casts

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

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp
index f5e692deeb782..e7577ac9dd7c5 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp
@@ -150,8 +150,7 @@ static bool printOp(const DWARFExpression::Operation *Op, raw_ostream &OS,
       } else if (Size == DWARFExpression::Operation::SizeBlock) {
         uint64_t Offset = Op->getRawOperand(Operand);
         for (unsigned i = 0; i < Op->getRawOperand(Operand - 1); ++i)
-          OS << formatv(" {0:x2}",
-                        static_cast<uint8_t>(Expr->getData()[Offset++]));
+          OS << formatv(" {0:x2}", Expr->getData()[Offset++]);
       } else {
         if (Signed)
           OS << formatv(" {0:+d}", (int64_t)Op->getRawOperand(Operand));
@@ -176,8 +175,7 @@ void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS,
     if (!printOp(&Op, OS, DumpOpts, E, U) && !DumpOpts.PrintRegisterOnly) {
       uint64_t FailOffset = Op.getEndOffset();
       while (FailOffset < E->getData().size())
-        OS << formatv(" {0:x-2}",
-                      static_cast<uint8_t>(E->getData()[FailOffset++]));
+        OS << formatv(" {0:x-2}", E->getData()[FailOffset++]);
       return;
     }
     if (!DumpOpts.PrintRegisterOnly) {



More information about the llvm-commits mailing list