[llvm] Allow DIDerivedType as a bound in DISubrangeType (PR #165880)
Michael Buch via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 23 15:38:09 PST 2025
Michael137 wrote:
> > For `DW_TAG_subrange_type`s of VLAs we just emit a `DW_AT_count` which references a variable DIE, which holds the dynamic element count. But that's not helpful here because you have a non-zero lower bound (and the variable holding the bound is a member variable, which we never have for VLAs)? So you want the same for `DW_AT_upper_bound` but be able to refer to a member variable? That seems reasonable to me (especially if GCC does this too).
>
> Yeah, basically. This particular change is about allowing an array bound to come from a "discriminant", which is a certain kind of field.
>
> In C terms it would be like if the `__counted_by` extension tried to emit array bounds in the DWARF.
>
> In Ada, either or both bounds can be treated this way, because in Ada all array types specify the ranges of their indices.
>
> > Could you briefly elaborate on this:
> > > gnat-llvm can then arrange for the DIE reference to be correct by setting the array type's scope to be the record.
> >
> >
> > How does that help determine the dynamic length?
>
> This ensures that the member DIEs are written first, so that the array bounds can refer to them.
I see, thanks for elaborating
So the DWARFv6 spec covers this with the following I think:
> 2.18 Static and Dynamic Values of Attributes
> ...
> – If the referenced entry represents a data member (e.g. has either a DW_AT_data_member_location or a DW_AT_data_bit_offset attribute), the attribute value is the value of the data member.
https://github.com/llvm/llvm-project/pull/165880
More information about the llvm-commits
mailing list