public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix IRA memory leak (PR middle-end/56461)
@ 2013-03-01 20:21 Jakub Jelinek
  2013-03-01 22:48 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2013-03-01 20:21 UTC (permalink / raw)
  To: Vladimir Makarov; +Cc: gcc-patches

Hi!

When ira_destroy is called, often (always?) this is after
loop_optimize_finalize call and thus current_loops is NULL, which results in
only freeing ira_loop_nodes[0] and not ira_loop_nodes[1] and above (if any).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2013-03-01  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/56461
	* ira-build.c (ira_loop_nodes_count): New variable.
	(create_loop_tree_nodes): Initialize it.
	(finish_loop_tree_nodes): Use it instead of looking at current_loops.

--- gcc/ira-build.c.jj	2013-02-08 13:16:55.000000000 +0100
+++ gcc/ira-build.c	2013-03-01 17:30:30.279549566 +0100
@@ -57,6 +57,9 @@ ira_loop_tree_node_t ira_bb_nodes;
    array.  */
 ira_loop_tree_node_t ira_loop_nodes;
 
+/* And size of the ira_loop_nodes array.  */
+unsigned int ira_loop_nodes_count;
+
 /* Map regno -> allocnos with given regno (see comments for
    allocno member `next_regno_allocno').  */
 ira_allocno_t *ira_regno_allocno_map;
@@ -142,14 +145,16 @@ create_loop_tree_nodes (void)
     }
   if (current_loops == NULL)
     {
+      ira_loop_nodes_count = 1;
       ira_loop_nodes = ((struct ira_loop_tree_node *)
 			ira_allocate (sizeof (struct ira_loop_tree_node)));
       init_loop_tree_node (ira_loop_nodes, 0);
       return;
     }
+  ira_loop_nodes_count = number_of_loops ();
   ira_loop_nodes = ((struct ira_loop_tree_node *)
 		    ira_allocate (sizeof (struct ira_loop_tree_node)
-				  * number_of_loops ()));
+				  * ira_loop_nodes_count));
   FOR_EACH_VEC_SAFE_ELT (get_loops (), i, loop)
     {
       if (loop_outer (loop) != NULL)
@@ -217,13 +222,9 @@ static void
 finish_loop_tree_nodes (void)
 {
   unsigned int i;
-  loop_p loop;
 
-  if (current_loops == NULL)
-    finish_loop_tree_node (&ira_loop_nodes[0]);
-  else
-    FOR_EACH_VEC_SAFE_ELT (get_loops (), i, loop)
-      finish_loop_tree_node (&ira_loop_nodes[i]);
+  for (i = 0; i < ira_loop_nodes_count; i++)
+    finish_loop_tree_node (&ira_loop_nodes[i]);
   ira_free (ira_loop_nodes);
   for (i = 0; i < (unsigned int) last_basic_block_before_change; i++)
     {

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix IRA memory leak (PR middle-end/56461)
  2013-03-01 20:21 [PATCH] Fix IRA memory leak (PR middle-end/56461) Jakub Jelinek
@ 2013-03-01 22:48 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2013-03-01 22:48 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Vladimir Makarov, gcc-patches

On 03/01/2013 01:21 PM, Jakub Jelinek wrote:
> Hi!
>
> When ira_destroy is called, often (always?) this is after
> loop_optimize_finalize call and thus current_loops is NULL, which results in
> only freeing ira_loop_nodes[0] and not ira_loop_nodes[1] and above (if any).
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2013-03-01  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR middle-end/56461
> 	* ira-build.c (ira_loop_nodes_count): New variable.
> 	(create_loop_tree_nodes): Initialize it.
> 	(finish_loop_tree_nodes): Use it instead of looking at current_loops.
OK.

Jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-01 22:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-01 20:21 [PATCH] Fix IRA memory leak (PR middle-end/56461) Jakub Jelinek
2013-03-01 22:48 ` Jeff Law

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).