aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch13.adb
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2019-08-20 09:50:38 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-08-20 09:50:38 +0000
commitb82f1618c4e8ca7dca229d1337e44873386561dc (patch)
tree49420f5a0fdab1e7dd0035516762c89709a8023a /gcc/ada/exp_ch13.adb
parentaa090e20d4bb02e829aa7e4d9e49ba06b94e0d5f (diff)
downloadgcc-b82f1618c4e8ca7dca229d1337e44873386561dc.zip
gcc-b82f1618c4e8ca7dca229d1337e44873386561dc.tar.gz
gcc-b82f1618c4e8ca7dca229d1337e44873386561dc.tar.bz2
[Ada] Crash on a Storage_Size aspect depending on attr. of another type
This patch fixes a crash on an aspect specification for Storage_Size for a type T when the expression for the aspect depends on attributes of a previously declared type that is not frozen yet. The temporary declaration that captures the value of the aspect must be part of the actions attached to the freeze node for T. 2019-08-20 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * exp_ch13.adb (Expand_N_Attribute_Definition_Clause, case Storage_Size): If the expression for Storage_Size is not static it may depend on characterstics of another type that may bot be frozen yet, so the elaboration of the expression for the aspect must be attached directly to the freeze actions of the type to which it applies. gcc/testsuite/ * gnat.dg/storage_size1.adb: New testcase. From-SVN: r274742
Diffstat (limited to 'gcc/ada/exp_ch13.adb')
-rw-r--r--gcc/ada/exp_ch13.adb40
1 files changed, 30 insertions, 10 deletions
diff --git a/gcc/ada/exp_ch13.adb b/gcc/ada/exp_ch13.adb
index f3c2c01..f3da4ee 100644
--- a/gcc/ada/exp_ch13.adb
+++ b/gcc/ada/exp_ch13.adb
@@ -220,9 +220,9 @@ package body Exp_Ch13 is
-- task_typeZ := expression
if Ekind (Ent) = E_Task_Type then
+
declare
Assign : Node_Id;
-
begin
Assign :=
Make_Assignment_Statement (Loc,
@@ -261,15 +261,35 @@ package body Exp_Ch13 is
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Ent), 'V'));
- -- Insert the declaration of the object
-
- Insert_Action (N,
- Make_Object_Declaration (Loc,
- Defining_Identifier => V,
- Object_Definition =>
- New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
- Expression =>
- Convert_To (RTE (RE_Storage_Offset), Expression (N))));
+ -- Insert the declaration of the object. If the expression
+ -- is not static it may depend on some other type that is
+ -- not frozen yet, so attach the declaration that captures
+ -- the value of the expression to the actions of the freeze
+ -- node of the current type.
+
+ declare
+ Decl : constant Node_Id :=
+ Make_Object_Declaration (Loc,
+ Defining_Identifier => V,
+ Object_Definition =>
+ New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
+ Expression =>
+ Convert_To
+ (RTE (RE_Storage_Offset), Expression (N)));
+ begin
+ if not Is_OK_Static_Expression (Expression (N))
+ and then Present (Freeze_Node (Ent))
+ then
+ if No (Actions (Freeze_Node (Ent))) then
+ Set_Actions (Freeze_Node (Ent), New_List (Decl));
+ else
+ Append (Decl, Actions (Freeze_Node (Ent)));
+ end if;
+
+ else
+ Insert_Action (N, Decl);
+ end if;
+ end;
Set_Storage_Size_Variable (Ent, Entity_Id (V));
end if;