public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Memory leak in concatenation with Initialize_Scalars
@ 2020-11-26  8:41 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-11-26  8:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: Bob Duff

[-- Attachment #1: Type: text/plain, Size: 313 bytes --]

This patch fixes a memory leak in concatenation when pragma
Initialize_Scalars or Normalize_Scalars is used.

Tested on x86_64-pc-linux-gnu, committed on trunk

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 948 bytes --]

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -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,



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-26  8:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26  8:41 [Ada] Memory leak in concatenation with Initialize_Scalars Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).