[Dwarf-Discuss] About self-referencial sized types

Robinson, Paul Paul_Robinson@playstation.sony.com
Wed May 14 19:48:15 GMT 2014

> -----Original Message-----
> From: dwarf-discuss-bounces at lists.dwarfstd.org [mailto:dwarf-discuss-
> bounces at lists.dwarfstd.org] On Behalf Of Pierre-Marie de Rodat
> Sent: Wednesday, May 14, 2014 5:39 AM
> To: Agovic, Sanimir
> Cc: DWARF Discuss
> Subject: Re: [Dwarf-Discuss] About self-referencial sized types
> On 04/28/2014 05:29 PM, Agovic, Sanimir wrote:
> >> In GCC, however, computing the upper bound of "A" is more subtle:
> >> it is internally represented as: max(0, <record>.N) so that when
> >> "N" is negative, 0 is returned.
> >
> > I`m not being familiar with internal gcc representations but what is
> > preventing you of referencing the member N?
> Nothing: actually, the internal GCC representation for Ada arrays bounds
> (GENERIC trees) is already there and works well for quite a while. My
> problem here is that I do not know what DWARF operations to output in
> the DW_AT_{lower,upper}_bound attributes in order to retrieve array
> "neighbors" members so that we can compute the array bounds using them.
> >> So what address would this operation [DW_OP_push_object_address]
> >> push on top of the stack? The address of the "A" member, or the
> >> address of the embedding record?
> >
> > It pushes the address of the currently evaluated object, in your
> > case it is the address of member "A". You may have a look at 'D.2
> > Aggregate Examples' and Figure 51 in the latest dwarf standard.
> > DW_OP_push_object_address is usually used to address meta information
> > of a type e.g. bound information of an array. This information is
> > usually part of the array descriptor hence the address of the object
> > is needed and not the embedding type.
> > Can you illustrate the record descriptor representation? e.g. a
> > simple representation in form of a C struct. My knowledge about how
> > vla work is pretty limited to C99 and Fortran. It might help to
> > understand the problem a bit better.
> Sure, I should have done it earlier. The Record_Type I was refering to
> in my example would be translated to something like:
>    struct record_type {
>      int n;
>      int a[1 .. max(n, 0)];
>    };

I had to do something like this for a COBOL compiler once, except
it was simply [1 .. N] and so I had the upper bound be a reference
to the member DIE for N.  If you're computing an expression on N
then yes it's more complicated.

In this case it seems like you could DW_OP_push_object_address to get
the address of "A", from there back up to the address of "N", fetch
it, and compute the max.

> >> On the other hand, getting the address of the "A" member would not
> >> be sufficient: in more complex cases, the offset of the "A" member
> >> can depend on discriminants!

Does that mean the offset between "A" and "N" is not constant?
You'd have to produce a sub-expression to compute that offset...
This sounds complicated but not infeasible.

More information about the Dwarf-discuss mailing list