From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [COMMITTED] ada: Fix internal error on 'Image applied to array component
Date: Tue, 16 May 2023 10:41:29 +0200 [thread overview]
Message-ID: <20230516084129.1502331-1-poulhies@adacore.com> (raw)
From: Eric Botcazou <ebotcazou@adacore.com>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/exp_imgv.adb | 23 +++++++++++++++++++++--
1 file 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;
--
2.40.0
reply other threads:[~2023-05-16 8:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230516084129.1502331-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).