[Ada] Attribute Img on derived types
authorEd Schonberg <schonberg@adacore.com>
Thu, 2 Jul 2020 00:25:09 +0000 (20:25 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 16 Oct 2020 07:34:43 +0000 (03:34 -0400)
gcc/ada/

* exp_imgv.adb (Expand_Image_Attribute): Refine previous patch
to use root type (and not base type) on enumeration types.

gcc/ada/exp_imgv.adb

index 731d01062e5366ac4f05d8ecd4c894d4932d3a61..a3c73fa4f099ebc239135da37d80281b6718def3 100644 (file)
@@ -481,9 +481,15 @@ package body Exp_Imgv is
 
       --  Ada 2020 allows 'Image on private types, so fetch the underlying
       --  type to obtain the structure of the type. We use the base type,
-      --  not the root type, to handle properly derived types.
+      --  not the root type, to handle properly derived types, but we use
+      --  the root type for enumeration types, because the literal map is
+      --  attached to the root. Should be inherited ???
 
-      Rtyp := Underlying_Type (Base_Type (Ptyp));
+      if Is_Enumeration_Type (Ptyp) then
+         Rtyp := Underlying_Type (Root_Type (Ptyp));
+      else
+         Rtyp := Underlying_Type (Base_Type (Ptyp));
+      end if;
 
       --  Enable speed-optimized expansion of user-defined enumeration types
       --  if we are compiling with optimizations enabled and enumeration type