[PATCH 14/21] PR jit/63854: Fix leak of paths within jump threading

2014-11-19 Thread David Malcolm
Paths are allocated as:
   vecjump_thread_edge * *path = new vecjump_thread_edge * ();
i.e. the vec itself is on the heap, so a mere:
  path-release ();
is merely releasing the buffer the vec holds, not the vec itself.

This patch updates the two sites that release paths to also delete them,
fixing leaks like this seen by valgrind:
160 bytes in 20 blocks are definitely lost in loss record 165 of 241
   at 0x4A06965: operator new(unsigned long) (in 
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x556E5AF: thread_across_edge(gimple_statement_base*, edge_def*, bool, 
vectree_node*, va_heap, vl_ptr*, tree_node
* (*)(gimple_statement_base*, gimple_statement_base*)) 
(tree-ssa-threadedge.c:1124)
   by 0x547B73B: dom_opt_dom_walker::thread_across_edge(edge_def*) 
(tree-ssa-dom.c:1184)
   by 0x5480183: dom_opt_dom_walker::after_dom_children(basic_block_def*) 
(tree-ssa-dom.c:2015)
   by 0x5C1C5F7: dom_walker::walk(basic_block_def*) (domwalk.c:218)
   by 0x547AE83: (anonymous namespace)::pass_dominator::execute(function*) 
(tree-ssa-dom.c:919)
   by 0x52235BD: execute_one_pass(opt_pass*) (passes.c:2306)
   by 0x5223834: execute_pass_list_1(opt_pass*) (passes.c:2358)
   by 0x5223865: execute_pass_list_1(opt_pass*) (passes.c:2359)
   by 0x52238A2: execute_pass_list(function*, opt_pass*) (passes.c:2369)
   by 0x4E4888F: cgraph_node::expand() (cgraphunit.c:1773)
   by 0x4E48F29: expand_all_functions() (cgraphunit.c:1909)

[Space-wise, a vec T, A, vl_ptr is just a pointer, hence the 8 bytes
per block seen in the valgrind report]

gcc/ChangeLog:
PR jit/63854
* tree-ssa-threadedge.c (thread_across_edge): Don't just release
path, delete it.
* tree-ssa-threadupdate.c (delete_jump_thread_path): Likewise.
---
 gcc/tree-ssa-threadedge.c   | 1 +
 gcc/tree-ssa-threadupdate.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index d5b9696..9ee1cae 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -1149,6 +1149,7 @@ thread_across_edge (gimple dummy_cond,
 through the vector entries.  */
   gcc_assert (path-length () == 0);
   path-release ();
+  delete path;
 
   /* A negative status indicates the target block was deemed too big to
 duplicate.  Just quit now rather than trying to use the block as
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 151ed83..5cb9f86 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2481,6 +2481,7 @@ delete_jump_thread_path (vecjump_thread_edge * *path)
   for (unsigned int i = 0; i  path-length (); i++)
 delete (*path)[i];
   path-release();
+  delete path;
 }
 
 /* Register a jump threading opportunity.  We queue up all the jump
-- 
1.8.5.3



Re: [PATCH 14/21] PR jit/63854: Fix leak of paths within jump threading

2014-11-19 Thread Richard Biener
On Wed, Nov 19, 2014 at 11:46 AM, David Malcolm dmalc...@redhat.com wrote:
 Paths are allocated as:
vecjump_thread_edge * *path = new vecjump_thread_edge * ();
 i.e. the vec itself is on the heap, so a mere:
   path-release ();
 is merely releasing the buffer the vec holds, not the vec itself.

Ok.

Thanks,
RIchard.

 This patch updates the two sites that release paths to also delete them,
 fixing leaks like this seen by valgrind:
 160 bytes in 20 blocks are definitely lost in loss record 165 of 241
at 0x4A06965: operator new(unsigned long) (in 
 /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x556E5AF: thread_across_edge(gimple_statement_base*, edge_def*, bool, 
 vectree_node*, va_heap, vl_ptr*, tree_node
 * (*)(gimple_statement_base*, gimple_statement_base*)) 
 (tree-ssa-threadedge.c:1124)
by 0x547B73B: dom_opt_dom_walker::thread_across_edge(edge_def*) 
 (tree-ssa-dom.c:1184)
by 0x5480183: dom_opt_dom_walker::after_dom_children(basic_block_def*) 
 (tree-ssa-dom.c:2015)
by 0x5C1C5F7: dom_walker::walk(basic_block_def*) (domwalk.c:218)
by 0x547AE83: (anonymous namespace)::pass_dominator::execute(function*) 
 (tree-ssa-dom.c:919)
by 0x52235BD: execute_one_pass(opt_pass*) (passes.c:2306)
by 0x5223834: execute_pass_list_1(opt_pass*) (passes.c:2358)
by 0x5223865: execute_pass_list_1(opt_pass*) (passes.c:2359)
by 0x52238A2: execute_pass_list(function*, opt_pass*) (passes.c:2369)
by 0x4E4888F: cgraph_node::expand() (cgraphunit.c:1773)
by 0x4E48F29: expand_all_functions() (cgraphunit.c:1909)

 [Space-wise, a vec T, A, vl_ptr is just a pointer, hence the 8 bytes
 per block seen in the valgrind report]

 gcc/ChangeLog:
 PR jit/63854
 * tree-ssa-threadedge.c (thread_across_edge): Don't just release
 path, delete it.
 * tree-ssa-threadupdate.c (delete_jump_thread_path): Likewise.
 ---
  gcc/tree-ssa-threadedge.c   | 1 +
  gcc/tree-ssa-threadupdate.c | 1 +
  2 files changed, 2 insertions(+)

 diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
 index d5b9696..9ee1cae 100644
 --- a/gcc/tree-ssa-threadedge.c
 +++ b/gcc/tree-ssa-threadedge.c
 @@ -1149,6 +1149,7 @@ thread_across_edge (gimple dummy_cond,
  through the vector entries.  */
gcc_assert (path-length () == 0);
path-release ();
 +  delete path;

/* A negative status indicates the target block was deemed too big to
  duplicate.  Just quit now rather than trying to use the block as
 diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
 index 151ed83..5cb9f86 100644
 --- a/gcc/tree-ssa-threadupdate.c
 +++ b/gcc/tree-ssa-threadupdate.c
 @@ -2481,6 +2481,7 @@ delete_jump_thread_path (vecjump_thread_edge * *path)
for (unsigned int i = 0; i  path-length (); i++)
  delete (*path)[i];
path-release();
 +  delete path;
  }

  /* Register a jump threading opportunity.  We queue up all the jump
 --
 1.8.5.3