Skip to content

Commit c2ef022

Browse files
authored
Omit member size from DWARF when desired (#161423)
1 parent 3c8c500 commit c2ef022

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,11 +1889,12 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
18891889
bool IsBitfield = DT->isBitField();
18901890

18911891
// Handle the size.
1892-
if (auto *Var = dyn_cast_or_null<DIVariable>(DT->getRawSizeInBits())) {
1892+
if (DT->getRawSizeInBits() == nullptr) {
1893+
// No size, just ignore.
1894+
} else if (auto *Var = dyn_cast<DIVariable>(DT->getRawSizeInBits())) {
18931895
if (auto *VarDIE = getDIE(Var))
18941896
addDIEEntry(MemberDie, dwarf::DW_AT_bit_size, *VarDIE);
1895-
} else if (auto *Exp =
1896-
dyn_cast_or_null<DIExpression>(DT->getRawSizeInBits())) {
1897+
} else if (auto *Exp = dyn_cast<DIExpression>(DT->getRawSizeInBits())) {
18971898
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
18981899
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
18991900
DwarfExpr.setMemoryLocationKind();

llvm/test/DebugInfo/X86/dynamic-bitfield.ll

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ source_filename = "bitfield.c"
2727
!6 = !{}
2828
!7 = !{!0, !2}
2929
!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "PackedBits", file: !5, line: 3, size: 40, elements: !9)
30-
!9 = !{!10, !12, !16}
30+
!9 = !{!10, !12, !16, !21}
3131
!10 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !8, file: !5, line: 5, baseType: !11, size: 8)
3232
; CHECK: DW_TAG_member
3333
; CHECK-NEXT: DW_AT_name{{.*}}"a"
@@ -60,5 +60,14 @@ source_filename = "bitfield.c"
6060
; CHECK: DW_AT_bit_size [DW_FORM_exprloc] (DW_OP_lit27)
6161
; CHECK-NEXT: DW_AT_data_bit_offset [DW_FORM_exprloc] (DW_OP_lit13)
6262
; CHECK-NOT: DW_AT_data_member_location
63-
; CHECK: DW_TAG
6463
!20 = !{!"clang version 3.9.0 (trunk 267633)"}
64+
!21 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !8, file: !5, line: 7, baseType: !13, offset: !DIExpression(DW_OP_constu, 15), flags: DIFlagBitField)
65+
; CHECK: DW_TAG_member
66+
; CHECK-NEXT: DW_AT_name{{.*}}"d"
67+
; CHECK-NOT: DW_TAG
68+
; CHECK-NOT: DW_AT_bit_offset
69+
; CHECK-NOT: DW_AT_byte_size
70+
; CHECK-NOT: DW_AT_bit_size
71+
; CHECK: DW_AT_data_bit_offset [DW_FORM_exprloc] (DW_OP_lit15)
72+
; CHECK-NOT: DW_AT_data_member_location
73+
; CHECK: DW_TAG

0 commit comments

Comments
 (0)