Running testsuite/jit.dg/test-functions.c under valgrind showed this leak (amongst others):
400 bytes in 10 blocks are definitely lost in loss record 142 of 181 at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x5DCDF2F: xrealloc (xmalloc.c:177) by 0x53726CE: void va_heap::reserve<gimple_statement_base*>(vec<gimple_statement_base*, va_heap, vl_embed>*&, unsigned int, bool) (vec.h:310) by 0x5371BB1: vec<gimple_statement_base*, va_heap, vl_ptr>::reserve(unsigned int, bool) (vec.h:1428) by 0x5370F5D: vec<gimple_statement_base*, va_heap, vl_ptr>::safe_push(gimple_statement_base* const&) (vec.h:1537) by 0x5523E71: maybe_record_sincos(vec<gimple_statement_base*, va_heap, vl_ptr>*, basic_block_def**, gimple_statement_base*) (tree-ssa-math-opts.c:718) by 0x552403E: execute_cse_sincos_1(tree_node*) (tree-ssa-math-opts.c:760) by 0x5526224: (anonymous namespace)::pass_cse_sincos::execute(function*) (tree-ssa-math-opts.c:1497) by 0x5250095: execute_one_pass(opt_pass*) (passes.c:2311) by 0x525030C: execute_pass_list_1(opt_pass*) (passes.c:2363) by 0x525033D: execute_pass_list_1(opt_pass*) (passes.c:2364) by 0x525037A: execute_pass_list(function*, opt_pass*) (passes.c:2374) For some reason (which I've filed for myself as PR jit/64020), this code was bailing out: fndecl = mathfn_built_in (type, BUILT_IN_CEXPI); if (!fndecl) return false; That exit path is missing a: stmts.release (); and thus is leaking the buffer of stmts on the way out. Fix it by converting stmts from vec<> to auto_vec<>, to avoid the need to have handwritten release calls on every exit path. gcc/ChangeLog: PR jit/63854 * tree-ssa-math-opts.c (execute_cse_sincos_1): Fix a missing release of stmts by converting it to an auto_vec. --- gcc/tree-ssa-math-opts.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index f9c30bf..5e08c7ee 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -740,7 +740,7 @@ execute_cse_sincos_1 (tree name) tree fndecl, res, type; gimple def_stmt, use_stmt, stmt; int seen_cos = 0, seen_sin = 0, seen_cexpi = 0; - vec<gimple> stmts = vNULL; + auto_vec<gimple> stmts; basic_block top_bb = NULL; int i; bool cfg_changed = false; @@ -773,10 +773,7 @@ execute_cse_sincos_1 (tree name) } if (seen_cos + seen_sin + seen_cexpi <= 1) - { - stmts.release (); - return false; - } + return false; /* Simply insert cexpi at the beginning of top_bb but not earlier than the name def statement. */ @@ -835,8 +832,6 @@ execute_cse_sincos_1 (tree name) cfg_changed = true; } - stmts.release (); - return cfg_changed; } -- 1.8.5.3