[Ada] Memory leak in concatenation with Initialize_Scalars
authorBob Duff <duff@adacore.com>
Fri, 23 Oct 2020 21:27:34 +0000 (17:27 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 26 Nov 2020 08:39:49 +0000 (03:39 -0500)
gcc/ada/

* exp_ch4.adb (Expand_Concatenate): Call Set_No_Initialization
on the N_Allocator node that is supposed to allocate on the
secondary stack.

gcc/ada/exp_ch4.adb

index 6899e620763e889db9a7d7ddfcb074943f57bb43..e0a62be1c48ed658419eca6eb415307587e1d383 100644 (file)
@@ -3505,8 +3505,17 @@ package body Exp_Ch4 is
             Alloc :=
               Make_Allocator (Loc,
                 Expression => New_Occurrence_Of (ConstrT, Loc));
+
+            --  Allocate on the secondary stack. This is currently done
+            --  only for type String, which normally doesn't have default
+            --  initialization, but we need to Set_No_Initialization in case
+            --  of Initialize_Scalars or Normalize_Scalars; otherwise, the
+            --  allocator will get transformed and will not use the secondary
+            --  stack.
+
             Set_Storage_Pool (Alloc, RTE (RE_SS_Pool));
             Set_Procedure_To_Call (Alloc, RTE (RE_SS_Allocate));
+            Set_No_Initialization (Alloc);
 
             Temp := Make_Temporary (Loc, 'R', Alloc);
             Insert_Action (Cnode,