[llvm] [Dwarf] Emit `DW_AT_bit_size` for non-byte-sized types (PR #137118)

Tom Tromey via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 24 06:30:06 PDT 2025


================
@@ -1749,6 +1749,10 @@ void DwarfCompileUnit::createBaseTypeDIEs() {
     // Round up to smallest number of bytes that contains this number of bits.
     addUInt(Die, dwarf::DW_AT_byte_size, std::nullopt,
             divideCeil(Btr.BitSize, 8));
+    // If the size is not a multiple of 8 (e.g., boolean), add the bit size
+    // field.
+    if (Btr.BitSize % 8 != 0)
+      addUInt(Die, dwarf::DW_AT_bit_size, std::nullopt, Btr.BitSize);
----------------
tromey wrote:

DWARF seems to say that either the bit- or byte-size should be specified.  So rather than emit both sizes, I think it's preferable to emit just the bit size if it is not a multiple of 8.  See DWARF 5 section 5.1 "Base Type Entries":
> A base type entry has a DW_AT_byte_size attribute or a
DW_AT_bit_size attribute whose integer constant value (see Section 2.21 on
page 56) is the amount of storage needed to hold a value of the type.

https://github.com/llvm/llvm-project/pull/137118


More information about the llvm-commits mailing list