[llvm] [DWARF] Fix DW_OP_LLVM_user sub-operation name lookup. (PR #217480)

Matt Davis via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 04:20:38 PDT 2026


https://github.com/enferex updated https://github.com/llvm/llvm-project/pull/217480

>From 79fc615278ed352ed92c6fc3af9d5c79d243d82d Mon Sep 17 00:00:00 2001
From: Matt Davis <mattd at nvidia.com>
Date: Wed, 19 Aug 2026 20:32:52 +0000
Subject: [PATCH 1/2] [DWARF] Fix DW_OP_LLVM_user sub-operation name lookup.

LlvmUserOperationEncodingString returns a name with a "DW_OP_LLVM_" prefix,
but getLlvmUserOperationEncoding matched the suffix (subop) name. This
patch updates the latter to match the full name.

Assisted-by: LLM
---
 llvm/lib/BinaryFormat/Dwarf.cpp           | 3 ++-
 llvm/unittests/BinaryFormat/DwarfTest.cpp | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/BinaryFormat/Dwarf.cpp b/llvm/lib/BinaryFormat/Dwarf.cpp
index 0027f1bbf0d9b..d130af6cc3adc 100644
--- a/llvm/lib/BinaryFormat/Dwarf.cpp
+++ b/llvm/lib/BinaryFormat/Dwarf.cpp
@@ -192,7 +192,8 @@ static StringRef LlvmUserOperationEncodingString(unsigned Encoding) {
 static unsigned
 getLlvmUserOperationEncoding(StringRef LlvmUserOperationEncodingString) {
   unsigned E = StringSwitch<unsigned>(LlvmUserOperationEncodingString)
-#define HANDLE_DW_OP_LLVM_USEROP(ID, NAME) .Case(#NAME, DW_OP_LLVM_##NAME)
+#define HANDLE_DW_OP_LLVM_USEROP(ID, NAME)                                     \
+  .Case("DW_OP_LLVM_" #NAME, DW_OP_LLVM_##NAME)
 #include "llvm/BinaryFormat/Dwarf.def"
                    .Default(0);
   assert(E && "unhandled DWARF operation string with LLVM user op");
diff --git a/llvm/unittests/BinaryFormat/DwarfTest.cpp b/llvm/unittests/BinaryFormat/DwarfTest.cpp
index c9522226c6031..1b3651555dda4 100644
--- a/llvm/unittests/BinaryFormat/DwarfTest.cpp
+++ b/llvm/unittests/BinaryFormat/DwarfTest.cpp
@@ -57,6 +57,13 @@ TEST(DwarfTest, getOperationEncoding) {
   EXPECT_EQ(0u, getOperationEncoding("DW_OP_hi_user"));
 }
 
+TEST(DwarfTest, SubOperationEncoding) {
+  EXPECT_EQ("DW_OP_LLVM_nop",
+            SubOperationEncodingString(DW_OP_LLVM_user, DW_OP_LLVM_nop));
+  EXPECT_EQ(DW_OP_LLVM_nop,
+            getSubOperationEncoding(DW_OP_LLVM_user, "DW_OP_LLVM_nop"));
+}
+
 TEST(DwarfTest, LanguageStringOnInvalid) {
   // This is invalid, so it shouldn't be stringified.
   EXPECT_EQ(StringRef(), LanguageString(0));

>From 64473cc2f1228eff0c5f954acf6bf73f0958be13 Mon Sep 17 00:00:00 2001
From: Matt Davis <mattd at nvidia.com>
Date: Thu, 20 Aug 2026 11:20:04 +0000
Subject: [PATCH 2/2] Added comment to the user string-to-enum roundtrip test.

---
 llvm/unittests/BinaryFormat/DwarfTest.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/unittests/BinaryFormat/DwarfTest.cpp b/llvm/unittests/BinaryFormat/DwarfTest.cpp
index 1b3651555dda4..c7e47a15852fd 100644
--- a/llvm/unittests/BinaryFormat/DwarfTest.cpp
+++ b/llvm/unittests/BinaryFormat/DwarfTest.cpp
@@ -58,6 +58,7 @@ TEST(DwarfTest, getOperationEncoding) {
 }
 
 TEST(DwarfTest, SubOperationEncoding) {
+  // Test that the enum-to-string user encodings roundtrip.
   EXPECT_EQ("DW_OP_LLVM_nop",
             SubOperationEncodingString(DW_OP_LLVM_user, DW_OP_LLVM_nop));
   EXPECT_EQ(DW_OP_LLVM_nop,



More information about the llvm-commits mailing list