[all-commits] [llvm/llvm-project] efbbca: [llvm][DebugInfo] Allow DIDerivedType as a bound i...

Tom Tromey via All-commits all-commits at lists.llvm.org
Wed Dec 3 16:38:35 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: efbbca62d15271b07c54b22a0014339f350c857f
      https://github.com/llvm/llvm-project/commit/efbbca62d15271b07c54b22a0014339f350c857f
  Author: Tom Tromey <tromey at adacore.com>
  Date:   2025-12-04 (Thu, 04 Dec 2025)

  Changed paths:
    M llvm/include/llvm/IR/DebugInfoMetadata.h
    M llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    M llvm/lib/IR/DebugInfoMetadata.cpp
    M llvm/lib/IR/Verifier.cpp
    A llvm/test/DebugInfo/X86/derived-in-subrange.ll

  Log Message:
  -----------
  [llvm][DebugInfo] Allow DIDerivedType as a bound in DISubrangeType (#165880)

Consider this Ada type:

```
   type Array_Type is array (Natural range <>) of Integer;
   type Record_Type (L1, L2 : Natural) is record
      I1 : Integer;
      A1 : Array_Type (1 .. L1);
      I2 : Integer;
      A2 : Array_Type (1 .. L2);
      I3 : Integer;
   end record;
```

Here, the array fields have lengths that depend on the discriminants of
the record type. However, in this case the array lengths cannot be
expressed as DWARF location expressions, with the issue being that "A2"
has a non-constant offset, but an expression involving
DW_OP_push_object_address will push the address of the field -- with no
way to find the location of "L2".

In a case like this, I believe the correct DWARF is to emit the array
ranges using a direct reference to the discriminant, like:

```
 <3><1156>: Abbrev Number: 1 (DW_TAG_member)
    <1157>   DW_AT_name        : l1
...
 <3><1177>: Abbrev Number: 6 (DW_TAG_array_type)
    <1178>   DW_AT_name        : (indirect string, offset: 0x1a0b): vla__record_type__T4b
    <117c>   DW_AT_type        : <0x1287>
    <1180>   DW_AT_sibling     : <0x118e>
 <4><1184>: Abbrev Number: 7 (DW_TAG_subrange_type)
    <1185>   DW_AT_type        : <0x1280>
    <1189>   DW_AT_upper_bound : <0x1156>
```

(FWIW this is what GCC has done for years.)

This patch makes this possible in LLVM, by letting a DISubrangeType
refer to a DIDerivedType. gnat-llvm can then arrange for the DIE
reference to be correct by setting the array type's scope to be the
record.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list