]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Crash on a Storage_Size aspect depending on attr. of another type
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Aug 2019 09:50:38 +0000 (09:50 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Aug 2019 09:50:38 +0000 (09:50 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274742 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/exp_ch13.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/storage_size1.adb [new file with mode: 0644]

index f914d0676d3fe1b6ee2abf2977549c6f23ded2f4..ee54d2742d50de3d310a3f70e14eb85827707b0d 100644 (file)
@@ -1,3 +1,12 @@
+2019-08-20  Ed Schonberg  <schonberg@adacore.com>
+
+       * 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.
+
 2019-08-20  Piotr Trojanek  <trojanek@adacore.com>
 
        * exp_util.adb (Build_DIC_Procedure_Declaration): Set the last
index f3c2c01240ba2a389703a301587ff15f37b50d75..f3da4eefa1a2ceecf20787ccb452e63b027ceb31 100644 (file)
@@ -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;
index b330c78955a99416401926dc724787a530cdb193..f18ea5f7dd1bc8cbac14353f6b07a0e1dc0cf7c7 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-20  Ed Schonberg  <schonberg@adacore.com>
+
+       * gnat.dg/storage_size1.adb: New testcase.
+
 2019-08-20  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/loop_entry2.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/storage_size1.adb b/gcc/testsuite/gnat.dg/storage_size1.adb
new file mode 100644 (file)
index 0000000..970caf1
--- /dev/null
@@ -0,0 +1,19 @@
+--  { dg-do compile }
+
+with Ada.Text_IO; with Ada.Integer_Text_IO;
+
+procedure Storage_Size1 is
+
+  package O renames Ada.Text_IO;
+  package T renames Ada.Integer_Text_IO;
+
+  type Struct is record first, second: Integer; end record;
+
+  type SP is access Struct
+      with Storage_Size => 64 * Struct'Max_Size_In_Storage_Elements;
+
+begin
+
+  T.Put(SP'Storage_Size); O.New_Line(1);
+
+end Storage_Size1;