From: Martin Liska Date: Thu, 27 Nov 2014 15:36:10 +0000 (+0100) Subject: IPA ICF: fix memory leak. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c190efccf0bd045b1b4ab4316e17a4674698cca8;p=gcc.git IPA ICF: fix memory leak. * ipa-icf.c (sem_function::equals_private): int* is replaced with auto_vec. (sem_function::bb_dict_test): Likewise. * ipa-icf.h: Likewise. Co-Authored-By: David Malcolm From-SVN: r218129 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dad0704a4e2..262cc7482fd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-11-27 Martin Liska + David Malcolm + + * ipa-icf.c (sem_function::equals_private): int* is replaced with + auto_vec. + (sem_function::bb_dict_test): Likewise. + * ipa-icf.h: Likewise. + 2014-11-27 Richard Biener PR middle-end/64088 diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index e0633e762f2..b1932008f65 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -410,7 +410,6 @@ sem_function::equals_private (sem_item *item, basic_block bb1, bb2; edge e1, e2; edge_iterator ei1, ei2; - int *bb_dict = NULL; bool result = true; tree arg1, arg2; @@ -486,12 +485,11 @@ sem_function::equals_private (sem_item *item, dump_message ("All BBs are equal\n"); + auto_vec bb_dict; + /* Basic block edges check. */ for (unsigned i = 0; i < bb_sorted.length (); ++i) { - bb_dict = XNEWVEC (int, bb_sorted.length () + 2); - memset (bb_dict, -1, (bb_sorted.length () + 2) * sizeof (int)); - bb1 = bb_sorted[i]->bb; bb2 = m_compared_func->bb_sorted[i]->bb; @@ -957,9 +955,15 @@ sem_function::icf_handled_component_p (tree t) corresponds to TARGET. */ bool -sem_function::bb_dict_test (int* bb_dict, int source, int target) +sem_function::bb_dict_test (auto_vec bb_dict, int source, int target) { - if (bb_dict[source] == -1) + source++; + target++; + + if (bb_dict.length () <= (unsigned)source) + bb_dict.safe_grow_cleared (source + 1); + + if (bb_dict[source] == 0) { bb_dict[source] = target; return true; diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h index 046e858c6a8..8be61494bb9 100644 --- a/gcc/ipa-icf.h +++ b/gcc/ipa-icf.h @@ -275,7 +275,7 @@ private: /* Basic blocks dictionary BB_DICT returns true if SOURCE index BB corresponds to TARGET. */ - bool bb_dict_test (int* bb_dict, int source, int target); + bool bb_dict_test (auto_vec bb_dict, int source, int target); /* Iterates all tree types in T1 and T2 and returns true if all types are compatible. If COMPARE_POLYMORPHIC is set to true,