[Dwarf-Discuss] DW_TAG_enumeration with DW_AT_type and DW_AT_byte_size

Joel Brobecker brobecker@adacore.com
Wed Mar 26 15:16:16 GMT 2014


Hello,

I asked our Ada gurus at AdaCore for some confirmation and here are
Tuck's answers (who says "Hi Ron!" :-)):

> Ada in particular defines enumeration types in a way such that they have,
> in effect, a definite underlying base integer type. This affects some
> details of type conversion between integer and enumeration types as well as
> allocation in composite types.

This seems a bit confused.  By default, the 'Size of an enumeration
type or subtype is strictly determined by the minimum number of bits
required to represent every value of the (sub)type -- this typically
matches the number of bits used for a component of a packed record.
The user may specify a 'Size, which must be no smaller than this
minimum size, and if it is feasible to allocate objects of exactly the
specified 'Size, that size is used.  In the absence of a specified
'Size, the compiler can allocate any size it chooses, allocating
different sizes in different contexts (e.g. an array element might get
a byte while a stand-alone object might get a word).

> [I also asked: Does the "base integer type" make no sense in the
> context of the language, then?]

As far as the language is concerned, there is no such notion.  As far
as any given implementation is concerned, there presumably is some
integer type that is chosen, but as indicated, it need not use the
same underlying integer type for each object of a given enumeration
type -- it can choose different sizes based on context.

> Subtypes of an enumeration type (representable as subrange types in DWARF)
> can be given yet a different size--but I think that goes beyond the
> discussion here.

In Ada, you cannot specify the 'Size for a subtype, unless it is the
"first" subtype of a type.

Note that GNAT has additional specifiable attributes, in particular
'Object_Size, which may be specified for any subtype.

I hope it helps clarify the Ada side a little bit. AFAICT, there is
no reason why we wouldn't be able to "inherit" the base-type's size
if the enum size attribute is absent.

-- 
Joel




More information about the Dwarf-discuss mailing list