summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2023-01-26 18:16:14 +0100
committerMarc Poulhiès <poulhies@adacore.com>2023-05-16 10:30:58 +0200
commitae334957c7dbbf3db6b612cd6f5fe058877abac4 (patch)
treed534fa6542f5436c7c9761184a7b1fed4102e2e5
parent5f8a29bd3487a60cf513c4976769b7dc0113f227 (diff)
downloadgcc-ae334957c7dbbf3db6b612cd6f5fe058877abac4.tar.gz
ada: Fix internal error on 'Image applied to array component
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.
-rw-r--r--gcc/ada/exp_imgv.adb23
1 files changed, 21 insertions, 2 deletions
diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index 93fdb70306f..257f65badd0 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -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;