Ada: Fixes Image attribute for derived enumeration types.
The Ada compiler now correctly handles the Image attribute for derived enumeration types with representation clauses.
The Ada compiler was incorrectly fetching the root type when handling the Image attribute for derived enumeration types, bypassing representation clauses defined on the derived type itself. This commit ensures that the compiler respects representation clauses on derived enumeration types when generating the Image attribute, by sticking to base types. A new test case, gnat.dg/enum6.adb, validates the fix.
In Details
This commit addresses PR ada/125240 by modifying Expand_Image_Attribute in exp_imgv.adb. The change ensures that the expansion of the Image attribute for derived enumeration types considers the representation clause defined on the derived type, rather than incorrectly defaulting to the root type. Lit_Indexes and Lit_Strings fields are now defined only for root types. This fix is specific to the Ada front end and doesn't directly influence other parts of GCC.
For Context
In Ada, enumeration types define a set of named values. A representation clause can be used to specify the underlying integer values associated with each named value. The Image attribute returns a string representation of an enumeration value. This commit fixes an issue where the compiler would ignore the representation clause when generating the string representation for derived enumeration types, leading to incorrect output.