<div dir="ltr"><div dir="ltr">>Consider a type that is a subrange of an integral base type, with an<br>>explicitly specified bit size smaller than the bit width of a storage<br>>unit.<br>><br>>When used for a standalone variable, its byte size is the same as that<br>>of the base type, i.e., the type is padded to a whole unit.<br><br>The variable's size has to be at least that of the base type. But it could be</div><div dir="ltr">larger. Especially likely if it is in a register. Actually it could be smaller if the</div><div>compiler can prove the possible range of actual values is smaller than</div><div>allowed by the base type.</div><div dir="ltr"><br>>However, when used for a packed record type, however, it takes on the<br>>requested bit size, without any padding whatsoever.<br><br>That is the purpose and meaning of packed, yes.</div><div dir="ltr"><br>>Because of the different sizes, this requires two distinct types to be<br>>defined in debug info.<br><br>There is no basis for this claim AFAIK.</div><div dir="ltr"><br>>Despite sharing the same bounds, however, it seems that the bounds have<br>>to be explicitly mentioned in both types.</div><div dir="ltr"><br></div><div dir="ltr">Equally unfounded. The type char in C has a range of -128..127 even if</div><div dir="ltr">no bounds are explicitly given.<br><br>>That's because, AFAICT, when DW_AT_lower_bound is omitted in a<br>>DW_TAG_subrange_type, it is implied as either 0 or 1, depending on the<br>>source language, while DW_AT_upper bound is unknown.<br><br>Yes.</div><div dir="ltr"><br>>There doesn't seem to be any provision for the bounds to be inherited<br>>from the base type.</div><div dir="ltr"><br></div><div dir="ltr">The bounds of the subrange type do have to be within the bounds</div><div dir="ltr">of the basis type  (even if unknown).<br><br>>So now we have to resort to something like:<br><br>>  (x) DW_TAG_base_type<br> >   DW_AT_byte_size 1<br> >  [...]<br> >(y) DW_TAG_subrange_type<br> > DW_AT_name ...<br> >  DW_AT_type x<br> >  DW_AT_lower_bound L<br> >  DW_AT_upper_bound U<br> >  [...]<br> > (z) DW_TAG_subrange_type<br> >   DW_AT_type x (could it be y?)<br> >   DW_AT_bit_size N<br> >   DW_AT_lower_bound L<br> >   DW_AT_lower_bound U<br><br>Not so as stated above.<br><br></div><div dir="ltr">>but if we had the possibility of inheriting bounds from the base type,<br>>it could be:<br><br>>  (x) DW_TAG_base_type<br>>    DW_AT_byte_size 1<br>>    [...]<br>>  (y) DW_TAG_subrange_type<br>>    DW_AT_name ...<br>>    DW_AT_type x<br>>    DW_AT_lower_bound L<br>>    DW_AT_upper_bound U<br>>    [...]<br>>  (z) DW_TAG_subrange_type<br>>    DW_AT_type y<br>>    DW_AT_bit_size N<br>>    [bounds are inherited from y]<br><br>Subrange y seems unnecessary which will result in the range -4..3. If you want some other range then you can add DW_AT_lower_bound/upper bound (that specifies a range with at most 2**N possible values).</div><div dir="ltr"><br>>I realize that this could bring complications in case the inheritance is<br>>not immediate.  Say, the base type could be a DW_TAG_const_type variant<br>>of a subrange type.  So, if we were to allow this sort of inheritance of<br>>bounds, it should probably also cover multiple levels.<br><br><br>>A simpler alternative could be to have another tag, say<br>>DW_TAG_[un]padded_type, for a different-sized variant of a type.  As<br>>usual for such tags, other properties would be inherited, including the<br>>bounds.<br></div><div dir="ltr"><br></div><div>Because two base types are not needed in the first place, no additional tag is needed.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 14, 2024 at 3:00 AM Alexandre Oliva via Dwarf-discuss <<a href="mailto:dwarf-discuss@lists.dwarfstd.org">dwarf-discuss@lists.dwarfstd.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Consider a type that is a subrange of an integral base type, with an<br>
explicitly specified bit size smaller than the bit width of a storage<br>
unit.<br>
<br>
When used for a standalone variable, its byte size is the same as that<br>
of the base type, i.e., the type is padded to a whole unit.<br>
<br>
However, when used for a packed record type, however, it takes on the<br>
requested bit size, without any padding whatsoever.<br>
<br>
Because of the different sizes, this requires two distinct types to be<br>
defined in debug info.<br>
<br>
Despite sharing the same bounds, however, it seems that the bounds have<br>
to be explicitly mentioned in both types.<br>
<br>
That's because, AFAICT, when DW_AT_lower_bound is omitted in a<br>
DW_TAG_subrange_type, it is implied as either 0 or 1, depending on the<br>
source language, while DW_AT_upper bound is unknown.<br>
<br>
There doesn't seem to be any provision for the bounds to be inherited<br>
from the base type.<br>
<br>
So now we have to resort to something like:<br>
<br>
  (x) DW_TAG_base_type<br>
    DW_AT_byte_size 1<br>
    [...]<br>
  (y) DW_TAG_subrange_type<br>
    DW_AT_name ...<br>
    DW_AT_type x<br>
    DW_AT_lower_bound L<br>
    DW_AT_upper_bound U<br>
    [...]<br>
  (z) DW_TAG_subrange_type<br>
    DW_AT_type x (could it be y?)<br>
    DW_AT_bit_size N<br>
    DW_AT_lower_bound L<br>
    DW_AT_lower_bound U<br>
<br>
but if we had the possibility of inheriting bounds from the base type,<br>
it could be:<br>
<br>
  (x) DW_TAG_base_type<br>
    DW_AT_byte_size 1<br>
    [...]<br>
  (y) DW_TAG_subrange_type<br>
    DW_AT_name ...<br>
    DW_AT_type x<br>
    DW_AT_lower_bound L<br>
    DW_AT_upper_bound U<br>
    [...]<br>
  (z) DW_TAG_subrange_type<br>
    DW_AT_type y<br>
    DW_AT_bit_size N<br>
    [bounds are inherited from y]<br>
<br>
I realize that this could bring complications in case the inheritance is<br>
not immediate.  Say, the base type could be a DW_TAG_const_type variant<br>
of a subrange type.  So, if we were to allow this sort of inheritance of<br>
bounds, it should probably also cover multiple levels.<br>
<br>
<br>
A simpler alternative could be to have another tag, say<br>
DW_TAG_[un]padded_type, for a different-sized variant of a type.  As<br>
usual for such tags, other properties would be inherited, including the<br>
bounds.<br>
<br>
This feels like a waste of a tag, though; DW_TAG_subrange_type seems<br>
like it could be enough.<br>
<br>
-- <br>
Alexandre Oliva, happy hacker                    <a href="https://FSFLA.org/blogs/lxo/" rel="noreferrer" target="_blank">https://FSFLA.org/blogs/lxo/</a><br>
   Free Software Activist                           GNU Toolchain Engineer<br>
Disinformation flourishes because many people care deeply about injustice but<br>
very few check the facts.  Think Assange & Stallman.  The empires strike back<br>
-- <br>
Dwarf-discuss mailing list<br>
<a href="mailto:Dwarf-discuss@lists.dwarfstd.org" target="_blank">Dwarf-discuss@lists.dwarfstd.org</a><br>
<a href="https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss" rel="noreferrer" target="_blank">https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss</a><br>
</blockquote></div>