[Ada] Fix runtime stack overflow for out/in-out actuals without discr.
authorJavier Miranda <miranda@adacore.com>
Tue, 11 Dec 2018 11:10:02 +0000 (11:10 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 11 Dec 2018 11:10:02 +0000 (11:10 +0000)
2018-12-11  Javier Miranda  <miranda@adacore.com>

gcc/ada/

* exp_aggr.adb (Convert_To_Assignments): When gnerating C, do
not declare a temporary to initialize an aggregate assigned to
Out or In_Out parameters whose type has no discriminants. This
avoids stack overflow errors at runtime.

From-SVN: r266988

gcc/ada/ChangeLog
gcc/ada/exp_aggr.adb

index f242a2f..ba91b12 100644 (file)
@@ -1,3 +1,10 @@
+2018-12-11  Javier Miranda  <miranda@adacore.com>
+
+       * exp_aggr.adb (Convert_To_Assignments): When gnerating C, do
+       not declare a temporary to initialize an aggregate assigned to
+       Out or In_Out parameters whose type has no discriminants. This
+       avoids stack overflow errors at runtime.
+
 2018-12-11  Ed Schonberg  <schonberg@adacore.com>
 
        * exp_ch7.adb (Check_Unnesting_Elaboration_Code): Extend
index 1c1890f..64233a5 100644 (file)
@@ -4245,6 +4245,22 @@ package body Exp_Aggr is
            Build_Record_Aggr_Code (N, Typ, Target_Expr));
          Rewrite (Parent (N), Make_Null_Statement (Loc));
 
+      --  Generating C, do not declare a temporary to initialize an aggregate
+      --  assigned to Out or In_Out parameters whose type has no discriminants.
+      --  This avoids stack overflow errors at run time.
+
+      elsif Modify_Tree_For_C
+        and then Nkind (Parent (N)) = N_Assignment_Statement
+        and then Nkind (Name (Parent (N))) = N_Identifier
+        and then Ekind_In (Entity (Name (Parent (N))), E_Out_Parameter,
+                                                       E_In_Out_Parameter)
+        and then not Has_Discriminants (Etype (Entity (Name (Parent (N)))))
+      then
+         Target_Expr := New_Copy_Tree (Name (Parent (N)));
+         Insert_Actions (Parent (N),
+           Build_Record_Aggr_Code (N, Typ, Target_Expr));
+         Rewrite (Parent (N), Make_Null_Statement (Loc));
+
       else
          Temp := Make_Temporary (Loc, 'A', N);