public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Attribute Img on derived types
@ 2020-10-16  7:35 Pierre-Marie de Rodat
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Marie de Rodat @ 2020-10-16  7:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 432 bytes --]

Refinement of previous patch: the root type must be used for the image
of enumeration types, because the literal map is attached to the root
type even when derivations are present.
Fixes several ACATS and fixedbugs regressions involving 'Image.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

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

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 972 bytes --]

diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Ada] Attribute Img on derived types
@ 2020-10-16  7:35 Pierre-Marie de Rodat
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Marie de Rodat @ 2020-10-16  7:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

This patch fixes the handling of the Ada_2020 attribute Img when applied
to derived types. If the type is private it is necessary to retrieve a
non-private description of the type structure, by using an underlying
view (which crosses the privacy boundary). The underlying view is that
of the base type of the object, but not its root type, which might
ignore components of a type extension and produce spurious type errors.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	*  exp_imgv.adb (Expand_Image_Attribute): Use the base type
	instead of the root type when type of object is private. Remove
	Ada_2020 guard, because it has been checked during prior
	analysis. Use Underlying_Type in all cases, as it is a no-op on
	types that are not private.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1803 bytes --]

diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -479,14 +479,11 @@ package body Exp_Imgv is
 
       Ptyp := Entity (Pref);
 
-      --  Ada 2020 allows 'Image on private types, so we need to fetch the
-      --  underlying type.
+      --  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.
 
-      if Ada_Version >= Ada_2020 then
-         Rtyp := Underlying_Type (Root_Type (Ptyp));
-      else
-         Rtyp := Root_Type (Ptyp);
-      end if;
+      Rtyp := Underlying_Type (Base_Type (Ptyp));
 
       --  Enable speed-optimized expansion of user-defined enumeration types
       --  if we are compiling with optimizations enabled and enumeration type
@@ -657,9 +654,10 @@ package body Exp_Imgv is
             T : Entity_Id;
          begin
             --  In Ada 2020 we need the underlying type here, because 'Image is
-            --  allowed on private types.
+            --  allowed on private types. We have already checked the version
+            --  when resolving the attribute.
 
-            if Ada_Version >= Ada_2020 then
+            if Is_Private_Type (Ptyp) then
                T := Rtyp;
             else
                T := Ptyp;
@@ -683,9 +681,7 @@ package body Exp_Imgv is
          declare
             Conv : Node_Id;
          begin
-            if Ada_Version >= Ada_2020
-              and then Is_Private_Type (Etype (Expr))
-            then
+            if Is_Private_Type (Etype (Expr)) then
                if Is_Fixed_Point_Type (Rtyp) then
                   Conv := Convert_To (Tent, OK_Convert_To (Rtyp, Expr));
                else



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-16  7:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16  7:35 [Ada] Attribute Img on derived types Pierre-Marie de Rodat
  -- strict thread matches above, loose matches on Subject: below --
2020-10-16  7:35 Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).