Skip to content

Commit 037aa20

Browse files
committed
[Dwarf] Emit DW_AT_bit_size for non-byte-sized types
1 parent 0eb30b7 commit 037aa20

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,10 @@ void DwarfCompileUnit::createBaseTypeDIEs() {
17491749
// Round up to smallest number of bytes that contains this number of bits.
17501750
addUInt(Die, dwarf::DW_AT_byte_size, std::nullopt,
17511751
divideCeil(Btr.BitSize, 8));
1752+
// If the size is not a multiple of 8 (e.g., boolean), add the bit size
1753+
// field.
1754+
if (Btr.BitSize % 8 != 0)
1755+
addUInt(Die, dwarf::DW_AT_bit_size, std::nullopt, Btr.BitSize);
17521756

17531757
Btr.Die = &Die;
17541758
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; RUN: llc -mtriple=x86_64 -dwarf-version=5 -filetype=obj -O0 < %s | llvm-dwarfdump - | FileCheck %s
2+
3+
; CHECK: DW_TAG_base_type
4+
; CHECK-NEXT: DW_AT_name ("DW_ATE_unsigned_1")
5+
; CHECK-NEXT: DW_AT_encoding (DW_ATE_unsigned)
6+
; CHECK-NEXT: DW_AT_byte_size (0x01)
7+
; CHECK-NEXT: DW_AT_bit_size (0x01)
8+
9+
define void @main() !dbg !18 {
10+
entry:
11+
#dbg_value(i1 false, !22, !DIExpression(DW_OP_not, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value), !23)
12+
ret void, !dbg !24
13+
}
14+
15+
!llvm.dbg.cu = !{!0}
16+
!llvm.module.flags = !{!10, !11, !12, !13, !14, !15, !16}
17+
!llvm.ident = !{!17}
18+
19+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 21.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
20+
!1 = !DIFile(filename: "test.c", directory: "/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build", checksumkind: CSK_MD5, checksum: "100bdbce655d729c24c7c0e8523a58ae")
21+
!2 = !{!3, !6, !8}
22+
!3 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression())
23+
!4 = distinct !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true)
24+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
25+
!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
26+
!7 = distinct !DIGlobalVariable(name: "b", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true)
27+
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
28+
!9 = distinct !DIGlobalVariable(name: "c", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true)
29+
!10 = !{i32 7, !"Dwarf Version", i32 5}
30+
!11 = !{i32 2, !"Debug Info Version", i32 3}
31+
!12 = !{i32 1, !"wchar_size", i32 4}
32+
!13 = !{i32 8, !"PIC Level", i32 2}
33+
!14 = !{i32 7, !"PIE Level", i32 2}
34+
!15 = !{i32 7, !"uwtable", i32 2}
35+
!16 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
36+
!17 = !{!"clang version 21.0.0git"}
37+
!18 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 3, type: !19, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !21)
38+
!19 = !DISubroutineType(types: !20)
39+
!20 = !{null}
40+
!21 = !{!22}
41+
!22 = !DILocalVariable(name: "l_4516", scope: !18, file: !1, line: 4, type: !5)
42+
!23 = !DILocation(line: 0, scope: !18)
43+
!24 = !DILocation(line: 9, column: 1, scope: !18)

0 commit comments

Comments
 (0)