From 97463b2b878556e244a9aadad64228f9895ac735 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 12 Sep 2013 11:18:46 +0000 Subject: re PR tree-optimization/58396 (heap-use-after-free at gcc/tree-loop-distribution.c:1959) 2013-09-12 Richard Biener PR tree-optimization/58396 * tree-loop-distribution.c (create_rdg_edges): Free unused DDRs. (build_rdg): Take a loop-nest parameter, fix memleaks. (distribute_loop): Compute loop-nest here and pass it to build_rdg. From-SVN: r202521 --- gcc/ChangeLog | 7 +++++++ gcc/tree-loop-distribution.c | 39 +++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 16 deletions(-) (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f27a648..2e5d31a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2013-09-12 Richard Biener + + PR tree-optimization/58396 + * tree-loop-distribution.c (create_rdg_edges): Free unused DDRs. + (build_rdg): Take a loop-nest parameter, fix memleaks. + (distribute_loop): Compute loop-nest here and pass it to build_rdg. + 2013-09-12 Yuri Rumyantsev * config/i386/x86-tune.def: Turn on X86_TUNE_AVOID_MEM_OPND_FOR_CMOVE diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c index 43c3d91..a404e00 100644 --- a/gcc/tree-loop-distribution.c +++ b/gcc/tree-loop-distribution.c @@ -383,6 +383,8 @@ create_rdg_edges (struct graph *rdg, vec ddrs) FOR_EACH_VEC_ELT (ddrs, i, ddr) if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) create_rdg_edge_for_ddr (rdg, ddr); + else + free_dependence_relation (ddr); for (i = 0; i < rdg->n_vertices; i++) FOR_EACH_PHI_OR_STMT_DEF (def_p, RDG_STMT (rdg, i), @@ -519,50 +521,45 @@ free_rdg (struct graph *rdg) } /* Build the Reduced Dependence Graph (RDG) with one vertex per - statement of the loop nest, and one edge per data dependence or + statement of the loop nest LOOP_NEST, and one edge per data dependence or scalar dependence. */ static struct graph * -build_rdg (struct loop *loop) +build_rdg (vec loop_nest) { struct graph *rdg; - vec loop_nest; vec stmts; vec datarefs; vec dependence_relations; - loop_nest.create (3); - if (!find_loop_nest (loop, &loop_nest)) - { - loop_nest.release (); - return NULL; - } - + /* Create the RDG vertices from the stmts of the loop nest. */ stmts.create (10); - stmts_from_loop (loop, &stmts); + stmts_from_loop (loop_nest[0], &stmts); rdg = build_empty_rdg (stmts.length ()); datarefs.create (10); - if (!create_rdg_vertices (rdg, stmts, loop, &datarefs)) + if (!create_rdg_vertices (rdg, stmts, loop_nest[0], &datarefs)) { stmts.release (); + datarefs.release (); free_rdg (rdg); return NULL; } stmts.release (); + + /* Create the RDG edges from the data dependences in the loop nest. */ dependence_relations.create (100); if (!compute_all_dependences (datarefs, &dependence_relations, loop_nest, false) || !known_dependences_p (dependence_relations)) { - loop_nest.release (); + free_dependence_relations (dependence_relations); datarefs.release (); - dependence_relations.release (); free_rdg (rdg); return NULL; } - loop_nest.release (); create_rdg_edges (rdg, dependence_relations); dependence_relations.release (); + datarefs.release (); return rdg; } @@ -1809,8 +1806,16 @@ distribute_loop (struct loop *loop, vec stmts) gimple s; unsigned i; vec vertices; + vec loop_nest; - rdg = build_rdg (loop); + loop_nest.create (3); + if (!find_loop_nest (loop, &loop_nest)) + { + loop_nest.release (); + return 0; + } + + rdg = build_rdg (loop_nest); if (!rdg) { if (dump_file && (dump_flags & TDF_DETAILS)) @@ -1818,6 +1823,7 @@ distribute_loop (struct loop *loop, vec stmts) "FIXME: Loop %d not distributed: failed to build the RDG.\n", loop->num); + loop_nest.release (); return res; } @@ -1843,6 +1849,7 @@ distribute_loop (struct loop *loop, vec stmts) res = ldist_gen (loop, rdg, vertices); vertices.release (); free_rdg (rdg); + loop_nest.release (); return res; } -- cgit v1.1