From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Crash on limited array object with address clause
Date: Wed, 30 Jun 2021 05:30:46 -0400 [thread overview]
Message-ID: <20210630093046.GA2150@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 982 bytes --]
Compiler aborts on an object declaration for a limited array type,
when declaration includes an aggregate that must be built in place,
and declaration carries an aspect specification for Address of object.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_aggr.adb (Convert_Aggr_In_Object_Decl): After expansion of
the aggregate, the expression can be removed from the
declaration, except if the object is class-wide, in which case
the aggregate provides the actual type. In other cases the
presence of the expression may lead to spurious freezing issue.
* exp_ch3.adb (Expand_N_Object_Declaration): If the expression
in the declaration is an aggregate with delayed expansion (as is
the case for objects of a limited type, or a subsequent address
specification) the aggregate must be resolved at this point.
This resolution must not include expansion, because the
expansion of the enclosing declaration will construct the
necessary aggregate expansion.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1863 bytes --]
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4437,6 +4437,15 @@ package body Exp_Aggr is
end;
Set_No_Initialization (N);
+
+ -- After expansion the expression can be removed from the declaration
+ -- except if the object is class-wide, in which case the aggregate
+ -- provides the actual type.
+
+ if not Is_Class_Wide_Type (Etype (Obj)) then
+ Set_Expression (N, Empty);
+ end if;
+
Initialize_Discriminants (N, Typ);
end Convert_Aggr_In_Object_Decl;
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -30,6 +30,7 @@ with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Errout; use Errout;
+with Expander; use Expander;
with Exp_Aggr; use Exp_Aggr;
with Exp_Atag; use Exp_Atag;
with Exp_Ch4; use Exp_Ch4;
@@ -6985,12 +6986,16 @@ package body Exp_Ch3 is
-- happen when the aggregate is limited and the declared object
-- has a following address clause; it happens also when generating
-- C code for an aggregate that has an alignment or address clause
- -- (see Analyze_Object_Declaration).
+ -- (see Analyze_Object_Declaration). Resolution is done without
+ -- expansion because it will take place when the declaration
+ -- itself is expanded.
if (Is_Limited_Type (Typ) or else Modify_Tree_For_C)
and then not Analyzed (Expr)
then
+ Expander_Mode_Save_And_Set (False);
Resolve (Expr, Typ);
+ Expander_Mode_Restore;
end if;
Convert_Aggr_In_Object_Decl (N);
reply other threads:[~2021-06-30 9:30 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=20210630093046.GA2150@adacore.com \
--to=derodat@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).