| Issue |
208203
|
| Summary |
[lldb] lldb ignores DW_AT_bit_size when evaluating DW_OP_convert to _BitInt base types
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
firmiana402
|
Clang and GCC emit natural DWARF for C `_BitInt(31)` as a `DW_TAG_base_type` carrying both `DW_AT_byte_size = 4` and `DW_AT_bit_size = 31`.
When a value does not fully occupy the storage described by `DW_AT_byte_size`, `DW_AT_bit_size` describes the actual number of bits used to represent values of the type. DWARF specification defines `DW_OP_convert` as converting the top stack entry to the referenced base type.
LLDB derives the conversion width from `DW_AT_byte_size * 8` whenever a byte size is present, and only falls back to `DW_AT_bit_size` when there is no byte size. So a natural `_BitInt(31)` base type is converted as a 32-bit integer, ignoring its `DW_AT_bit_size = 31`.
The width is computed in `DWARFUnit::GetDIEBitSizeAndSign` (`DWARFUnit.cpp`), on the `DW_OP_convert` path:
```cpp
uint64_t bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
if (!bit_size)
bit_size = die.GetAttributeValueAsUnsigned(DW_AT_bit_size, 0);
```
`DW_AT_byte_size` takes priority: `DW_AT_bit_size` is consulted only when the byte size is absent. For `_BitInt(31)` emitted as `DW_AT_byte_size = 4, DW_AT_bit_size = 31`, this yields a width of `32` instead of `31`.
## Possible Fix
When a type carries both `DW_AT_bit_size` and `DW_AT_byte_size`, `DW_AT_bit_size` should take priority, since it describes the actual value width — rather than deriving the width from `DW_AT_byte_size * 8`. In other words, prefer `DW_AT_bit_size` when it is present and fall back to `DW_AT_byte_size * 8` only when it is absent, so that types like `_BitInt(31)` are converted at their true 31-bit width.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs