Skip to content

[llvm][AsmWriter] Don't skip zero-valued DwarfEnum MDField when ShouldSkipZero is not set #126044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Feb 6, 2025

I ran into this while working on a different patch where I'm emitting a zero-valued DWARF enum field which shouldn't be skipped.

This patch checks the (currently unused) ShouldSkipZero before deciding to skip printing this field. Based on git history this seems like an oversight from the initial refactor that introduced this. We have a similar check in printInt.

Wasn't sure how to best test this, but tests in an upcoming patch rely on this functionality (see #126045).

Currently the only place ShouldSkipZero is set to false is when emitting the DW_LANG_ enum. But the language codes start at 0x1. So it never exercised this codepath (and we should probably just make it not pass this parameter).

…dSkipZero is not set

I ran into this whil working on a different patch where I'm emitting a zero-valued DWARF enum field which shouldn't be skipped.

This patch checks the (currently unused) `ShouldSkipZero` before deciding to skip printing this field. Based on git history this seems like an oversight from the initial refactor that introduced this. We have a similar check in `printInt`.

Wasn't sure how to best test this, but tests in an upcoming patch rely on this functionality.
@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

@llvm/pr-subscribers-llvm-ir

Author: Michael Buch (Michael137)

Changes

I ran into this whil working on a different patch where I'm emitting a zero-valued DWARF enum field which shouldn't be skipped.

This patch checks the (currently unused) ShouldSkipZero before deciding to skip printing this field. Based on git history this seems like an oversight from the initial refactor that introduced this. We have a similar check in printInt.

Wasn't sure how to best test this, but tests in an upcoming patch rely on this functionality.

Currently the only place ShouldSkipZero is set to false is when emitting the DW_LANG_ enum. But the language codes start at 0x1. So it never exercised this codepath (and we should probably just make it not pass this parameter).


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

1 Files Affected:

  • (modified) llvm/lib/IR/AsmWriter.cpp (+1-1)
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index c8ed4e19f1b612..57e9cccdc0fb6e 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2004,7 +2004,7 @@ void MDFieldPrinter::printNameTableKind(StringRef Name,
 template <class IntTy, class Stringifier>
 void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value,
                                     Stringifier toString, bool ShouldSkipZero) {
-  if (!Value)
+  if (ShouldSkipZero && !Value)
     return;
 
   Out << FS << Name << ": ";

@Michael137 Michael137 merged commit 5492199 into llvm:main Feb 6, 2025
10 checks passed
Michael137 added a commit that referenced this pull request Feb 7, 2025
…#126045)

This is the 2nd part to
#124752. Here we make sure to
set the `DICompositeType` `EnumKind` if the enum was declared with
`__attribute__((enum_extensibility(...)))`. In DWARF this will be
rendered as `DW_AT_APPLE_enum_kind` and will be used by LLDB when
creating `clang::EnumDecl`s from debug-info.
 
Depends on #126044
github-actions bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 7, 2025
…y attribute (#126045)

This is the 2nd part to
llvm/llvm-project#124752. Here we make sure to
set the `DICompositeType` `EnumKind` if the enum was declared with
`__attribute__((enum_extensibility(...)))`. In DWARF this will be
rendered as `DW_AT_APPLE_enum_kind` and will be used by LLDB when
creating `clang::EnumDecl`s from debug-info.

Depends on llvm/llvm-project#126044
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…dSkipZero is not set (llvm#126044)

I ran into this while working on a different patch where I'm emitting a
zero-valued DWARF enum field which shouldn't be skipped.

This patch checks the (currently unused) `ShouldSkipZero` before
deciding to skip printing this field. Based on git history this seems
like an oversight from the initial refactor that introduced this. We
have a similar check in `printInt`.

Wasn't sure how to best test this, but tests in an upcoming patch rely
on this functionality (see
llvm#126045).

Currently the only place `ShouldSkipZero` is set to `false` is when
emitting the `DW_LANG_` enum. But the language codes start at `0x1`. So
it never exercised this codepath (and we should probably just make it
not pass this parameter).
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…llvm#126045)

This is the 2nd part to
llvm#124752. Here we make sure to
set the `DICompositeType` `EnumKind` if the enum was declared with
`__attribute__((enum_extensibility(...)))`. In DWARF this will be
rendered as `DW_AT_APPLE_enum_kind` and will be used by LLDB when
creating `clang::EnumDecl`s from debug-info.
 
Depends on llvm#126044
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants