Skip to content

[DWARF] Fix DW_OP_LLVM_user sub-operation name lookup. - #217480

Merged
enferex merged 2 commits into
llvm:mainfrom
enferex:dwarf-subop-name-roundtrip
Aug 20, 2026
Merged

[DWARF] Fix DW_OP_LLVM_user sub-operation name lookup.#217480
enferex merged 2 commits into
llvm:mainfrom
enferex:dwarf-subop-name-roundtrip

Conversation

@enferex

@enferex enferex commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

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
@llvmorg-github-actions

llvmorg-github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-llvm-binary-utilities

Author: Matt Davis (enferex)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/217480.diff

2 Files Affected:

  • (modified) llvm/lib/BinaryFormat/Dwarf.cpp (+2-1)
  • (modified) llvm/unittests/BinaryFormat/DwarfTest.cpp (+7)
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));

@echristo
echristo self-requested a review August 19, 2026 22:32
Comment thread llvm/unittests/BinaryFormat/DwarfTest.cpp
@enferex
enferex requested a review from echristo August 20, 2026 13:53
@ayermolo
ayermolo self-requested a review August 20, 2026 18:01

@echristo echristo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @slinder1 asked for this to be split out so let's wait for their ack.

@slinder1 slinder1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@enferex
enferex merged commit 4aa995f into llvm:main Aug 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants