[Lldb-commits] [lldb] [llvm] Emit DIE's size in bits when size is not a multiple of 8 (PR #69741)

David Blaikie via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 14 15:50:15 PST 2023


dwblaikie wrote:

> > I guess one question that might be relevant - does Swift have something like sizeof and what result does it give for these sort of types with bits to spare?
> 
> You can't actually use that with these types as these are special compiler builtin types which aren't actually accessible in source code.

Perhaps observable indirectly?
 
> > But like I said - it seems like structs with tail padding are similar to this situation - we still describe the whole size of the struct, because that's used for creating arrays of instances, ABI passing, etc. But the tail padding can still be used, in certain circumstances, when laying out a derived class. We encode this as the POD-ness of the type, and so if you wanted to create a class that derived from one described in DWARF you could do so & would know whether or not to put the derived class's members into the tail padding of the base or not.
> 
> I understand the rationale of basing this on precedent, but in this case in this case we should break from it for two reasons:
> 
> * DW_AT_BIT_SIZE is already a standardized attribute in Dwarf that fits this use case.

I'm arguing it doesn't fit it particularly well. We use it for bit fields - which are pretty special, for instance, but it seems like this thing isn't quite like that - it does have a whole byte size (if you allocated an array of them, for instance, I'm guessing they're a byte each, right?) but then has some padding bits that can be reused in some circumstances? That's why I'm saying it seems like it fits more closely to the struct padding representation.

> * Round up to the nearest byte would lose information, which can be kept with fairly minimal downsides in my opinion.

Seems like it'd still need to be special cased, right? The consumer would go "oh, this has a bit size, but if we want an array of them, or to allocate them for ABI purposes, etc, I have to round it up to the nearest byte"? or something like that.

Some pointers to documentation about these types, and the range of uses/instances there are might be handy (like is this a general concept? Or is it only one type that uses this (`bool` equivalent, with 7 padding bytes unused) or a class of types (a small finite list of them? Unbounded (like if I put a bool in my custom struct - does my custom struct end up with a bit size too?))

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


More information about the lldb-commits mailing list