[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 11:08:18 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:

I was looking at this again and there's some later text about a scenario where `DW_AT_byte_size` is used for the object size, but then the actual data is described with `DW_AT_bit_size` *plus* `DW_AT_data_bit_offset`.  So while it's not totally correct to say that the base type must have one or the other, it's still the case that this particular patch should probably do that.  IMO.

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


More information about the llvm-commits mailing list