[llvm] Omit member size from DWARF when desired (PR #161423)
Tom Tromey via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 2 08:52:11 PDT 2025
https://github.com/tromey updated https://github.com/llvm/llvm-project/pull/161423
>From a4b71a67c40f3feb792d2341f6c58318381ff554 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey at adacore.com>
Date: Tue, 30 Sep 2025 12:30:09 -0600
Subject: [PATCH] Omit member size from DWARF when desired
It's reasonably normal for DWARF not to explicitly state the size of a
member of a composite type -- in this case the size is taken from the
type. LLVM does allow a member to have a NULL size, but in this case
it emits a size of "0". This patch cleans this up a bit, changing the
DWARF emission code to simply not emit a size in this situation.
---
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 7 ++++---
llvm/test/DebugInfo/X86/dynamic-bitfield.ll | 13 +++++++++++--
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 62fb5eb011cf2..3cfe7cc12d5b6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1889,11 +1889,12 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
bool IsBitfield = DT->isBitField();
// Handle the size.
- if (auto *Var = dyn_cast_or_null<DIVariable>(DT->getRawSizeInBits())) {
+ if (DT->getRawSizeInBits() == nullptr) {
+ // No size, just ignore.
+ } else if (auto *Var = dyn_cast<DIVariable>(DT->getRawSizeInBits())) {
if (auto *VarDIE = getDIE(Var))
addDIEEntry(MemberDie, dwarf::DW_AT_bit_size, *VarDIE);
- } else if (auto *Exp =
- dyn_cast_or_null<DIExpression>(DT->getRawSizeInBits())) {
+ } else if (auto *Exp = dyn_cast<DIExpression>(DT->getRawSizeInBits())) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
diff --git a/llvm/test/DebugInfo/X86/dynamic-bitfield.ll b/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
index c9148ca4582f6..f8935977c64e7 100644
--- a/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
+++ b/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
@@ -27,7 +27,7 @@ source_filename = "bitfield.c"
!6 = !{}
!7 = !{!0, !2}
!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "PackedBits", file: !5, line: 3, size: 40, elements: !9)
-!9 = !{!10, !12, !16}
+!9 = !{!10, !12, !16, !21}
!10 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !8, file: !5, line: 5, baseType: !11, size: 8)
; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name{{.*}}"a"
@@ -60,5 +60,14 @@ source_filename = "bitfield.c"
; CHECK: DW_AT_bit_size [DW_FORM_exprloc] (DW_OP_lit27)
; CHECK-NEXT: DW_AT_data_bit_offset [DW_FORM_exprloc] (DW_OP_lit13)
; CHECK-NOT: DW_AT_data_member_location
-; CHECK: DW_TAG
!20 = !{!"clang version 3.9.0 (trunk 267633)"}
+!21 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !8, file: !5, line: 7, baseType: !13, offset: !DIExpression(DW_OP_constu, 15), flags: DIFlagBitField)
+; CHECK: DW_TAG_member
+; CHECK-NEXT: DW_AT_name{{.*}}"d"
+; CHECK-NOT: DW_TAG
+; CHECK-NOT: DW_AT_bit_offset
+; CHECK-NOT: DW_AT_byte_size
+; CHECK-NOT: DW_AT_bit_size
+; CHECK: DW_AT_data_bit_offset [DW_FORM_exprloc] (DW_OP_lit15)
+; CHECK-NOT: DW_AT_data_member_location
+; CHECK: DW_TAG
More information about the llvm-commits
mailing list