[PATCH] DWARF: make signedness explicit for enumerator const values

Mark Wielaard mark@klomp.org
Thu Nov 10 12:38:00 GMT 2016


On Thu, 2016-10-13 at 18:12 +0200, Pierre-Marie de Rodat wrote:
> Currently, the DWARF description does not specify the signedness of the
> representation of enumeration types.  This is a problem in some
> contexts where DWARF consumers need to determine if value X is greater
> than value Y.
> 
> For instance in Ada:
> 
>     type Enum_Type is ( A, B, C, D);
>     for Enum_Type use (-1, 0, 1, 2);
> 
>     type Rec_Type (E : Enum_Type) is record
>        when A .. B => null;
>        when others => B : Booleann;
>     end record;
> 
> The above can be described in DWARF the following way:
> 
>     DW_TAG_enumeration_type(Enum_Type)
>     | DW_AT_byte_size: 1
>       DW_TAG_enumerator(A)
>       | DW_AT_const_value: -1
>       DW_TAG_enumerator(B)
>       | DW_AT_const_value: 0
>       DW_TAG_enumerator(C)
>       | DW_AT_const_value: 1
>       DW_TAG_enumerator(D)
>       | DW_AT_const_value: 2
> 
>     DW_TAG_structure_type(Rec_Type)
>       DW_TAG_member(E)
>       | DW_AT_type: <Enum_Type>
>       DW_TAG_variant_part
>       | DW_AT_discr: <E>
>         DW_TAG_variant
>         | DW_AT_discr_list: DW_DSC_range 0x7f 0
>         DW_TAG_variant
>         | DW_TAG_member(b)
> 
> DWARF consumers need to know that enumerators (A, B, C and D) are signed
> in order to determine the set of E values for which Rec_Type has a B
> field.  In practice, they need to know how to interpret the 0x7f LEB128
> number above (-1, not 127).
> 
> There seems to be only two alternatives to solve this issue: one is to
> add a DW_AT_type attribute to DW_TAG_enumerator_type DIEs to make it
> point to a base type that specifies the signedness.  The other is to
> make sure the form of the DW_AT_const_value attribute carries the
> signedness information.  This patch implements the latter.

IMHO having an explicit DW_AT_type pointing at the base type with size
and encoding for the DW_TAG_enumerator_type is better for consumers than
having to try and interpret the DW_FORM used to encode the values.

Alternatively could we just attach a DW_AT_encoding to the
DW_TAG_enumeration_type? The spec doesn't list it as one of the
attributes for an enumeration_type, but it makes sense given it already
carries bit/byte size attributes.

Thanks,

Mark



More information about the Gcc-patches mailing list