[llvm] Allow DIDerivedType as a bound in DISubrangeType (PR #165880)

Tom Tromey via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 05:51:49 PST 2025


tromey 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.

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


More information about the llvm-commits mailing list