diff options
author | Ed Schonberg <schonberg@adacore.com> | 2021-04-16 12:52:50 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-06-29 14:23:48 +0000 |
commit | a671959b7640b1b02c924292959f2cbe1574536a (patch) | |
tree | 8f68ef3183b5bb11496267051c57626a483557c4 | |
parent | 38b57d67e85df1636c5e4300defe337e28878412 (diff) | |
download | gcc-a671959b7640b1b02c924292959f2cbe1574536a.zip gcc-a671959b7640b1b02c924292959f2cbe1574536a.tar.gz gcc-a671959b7640b1b02c924292959f2cbe1574536a.tar.bz2 |
[Ada] Crash on limited array object with address clause
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.
-rw-r--r-- | gcc/ada/exp_aggr.adb | 9 | ||||
-rw-r--r-- | gcc/ada/exp_ch3.adb | 7 |
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 85e2abb..56ec1be 100644 --- 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 index 6a8b330..4dbaadd 100644 --- 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); |