Hello.

Following patch removes memory leak that was introduced by very first IPA ICF 
patch.
I would like to thank David for hunting the leak.

Patch an bootstrap on x86_86-linux-pc and no regression is introduced.

Thanks,
Martin
>From f959905e984a84d0353fb1e32ba83db2b6dfe4d2 Mon Sep 17 00:00:00 2001
From: mliska <mli...@suse.cz>
Date: Fri, 21 Nov 2014 16:04:06 +0100
Subject: [PATCH] IPA ICF: memory leak fix

gcc/ChangeLog:

2014-11-21  David Malcolm  <dmalc...@redhat.com>
	    Martin Liska  <mli...@suse.cz>

	* ipa-icf.c (sem_function::equals_private): auto_vec<int> replaces
	int* allocated with XNEWVEC.
	(sem_function::bb_dict_test): Likewise.
	* ipa-icf.h: Likewise.
---
 gcc/ipa-icf.c | 15 ++++++++++-----
 gcc/ipa-icf.h |  2 +-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index e0633e7..4a0fcfb 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;
 
@@ -489,8 +488,8 @@ sem_function::equals_private (sem_item *item,
   /* 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));
+      auto_vec<int> bb_dict;
+      bb_dict.safe_grow_cleared (bb_sorted.length () + 2);
 
       bb1 = bb_sorted[i]->bb;
       bb2 = m_compared_func->bb_sorted[i]->bb;
@@ -957,9 +956,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<int> &bb_dict, int source, int target)
 {
-  if (bb_dict[source] == -1)
+  /* bb_dict is cleared with zeros, so that source and target are
+     incremented. bb_dist is used to verify that edges in source and
+     target function correspond. */
+
+  source++;
+  target++;
+  if (bb_dict[source] == 0)
     {
       bb_dict[source] = target;
       return true;
diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h
index 046e858..75db93a 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<int> &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,
-- 
2.1.2

Reply via email to