]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix internal error on 'Image applied to array component
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 26 Jan 2023 17:16:14 +0000 (18:16 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 27 Sep 2023 08:16:24 +0000 (10:16 +0200)
This happens because the array component depends on a discriminant.

gcc/ada/

* exp_imgv.adb (Rewrite_Object_Image): If the prefix is a component
that depends on a discriminant, create an actual subtype for it.

gcc/ada/exp_imgv.adb

index 93fdb70306fc822c15af582115452f4e2113c322..257f65badd0df0fc3714cb28f0c552f54dd282cc 100644 (file)
@@ -2498,12 +2498,31 @@ package body Exp_Imgv is
       Attr_Name : Name_Id;
       Str_Typ   : Entity_Id)
    is
+      Ptyp : Entity_Id;
+
    begin
+      Ptyp := Etype (Pref);
+
+      --  If the prefix is a component that depends on a discriminant, then
+      --  create an actual subtype for it.
+
+      if Nkind (Pref) = N_Selected_Component then
+         declare
+            Decl : constant Node_Id :=
+                     Build_Actual_Subtype_Of_Component (Ptyp, Pref);
+         begin
+            if Present (Decl) then
+               Insert_Action (N, Decl);
+               Ptyp := Defining_Identifier (Decl);
+            end if;
+         end;
+      end if;
+
       Rewrite (N,
         Make_Attribute_Reference (Sloc (N),
-          Prefix         => New_Occurrence_Of (Etype (Pref), Sloc (N)),
+          Prefix         => New_Occurrence_Of (Ptyp, Sloc (N)),
           Attribute_Name => Attr_Name,
-          Expressions    => New_List (Relocate_Node (Pref))));
+          Expressions    => New_List (Unchecked_Convert_To (Ptyp, Pref))));
 
       Analyze_And_Resolve (N, Str_Typ);
    end Rewrite_Object_Image;