From e64ac63149a6ec0ee9403079eea7df857ff59587 Mon Sep 17 00:00:00 2001 From: Javier Miranda Date: Tue, 11 Dec 2018 11:10:02 +0000 Subject: [PATCH] [Ada] Fix runtime stack overflow for out/in-out actuals without discr. 2018-12-11 Javier Miranda 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 | 7 +++++++ gcc/ada/exp_aggr.adb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index f242a2f..ba91b12 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2018-12-11 Javier Miranda + + * 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 * exp_ch7.adb (Check_Unnesting_Elaboration_Code): Extend diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 1c1890f..64233a5 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -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); -- 2.7.4