On 11/23/2014 10:01 AM, Markus Trippelsdorf wrote:
On 2014.11.22 at 17:46 +0100, Markus Trippelsdorf wrote:
On 2014.11.22 at 16:04 +0100, Martin Liška wrote:
On 11/22/2014 10:09 AM, Markus Trippelsdorf wrote:
On 2014.11.22 at 09:05 +0100, Martin Liška wrote:

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.

I gave the patch a quick spin on gcc112:

*** Error in `/home/trippels/gcc_build_dir/./prev-gcc/lto1': free(): invalid 
next size (fast): 0x000001000a5fc160 ***
======= Backtrace: =========
/lib64/libc.so.6(+0xa3d9c)[0x3fff7b6b3d9c]
/lib64/libc.so.6(+0xaf0b4)[0x3fff7b6bf0b4]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_ZN3vecIi7va_heap6vl_ptrE7releaseEv-0x1d4bc00)[0x1025dd88]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_ZN7ipa_icf12sem_function14equals_privateEPNS_8sem_itemER8hash_mapIP11symtab_nodeS2_22default_hashmap_traitsE-0x9c083c)[0x116586bc]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_ZN7ipa_icf12sem_function6equalsEPNS_8sem_itemER8hash_mapIP11symtab_nodeS2_22default_hashmap_traitsE-0x9c0578)[0x11658998]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_ZN7ipa_icf18sem_item_optimizer7executeEv-0x9b8774)[0x11660a84]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_ZN7ipa_icf12pass_ipa_icf7executeEP8function-0x9b0314)[0x11668efc]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_Z16execute_one_passP8opt_pass-0x1647588)[0x1098a0a8]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_Z21execute_ipa_pass_listP8opt_pass-0x1644c2c)[0x1098ca7c]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_Z8lto_mainv-0x1df20e4)[0x101b494c]
/home/trippels/gcc_build_dir/./prev-gcc/lto1[0x10b599b8]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(_ZN6toplev4mainEiPPc-0x1e8be70)[0x101507b8]
/home/trippels/gcc_build_dir/./prev-gcc/lto1(main-0x1ec8d8c)[0x1015493c]
/lib64/libc.so.6(+0x447ac)[0x3fff7b6547ac]
/lib64/libc.so.6(__libc_start_main-0x19cbf4)[0x3fff7b6549d4]
======= Memory map: ========
...


Thank you for testing, problem is that I should grow the vector by 1, because 
'0' is used as NULL value.

Please try my fixed patch.

This one survives bootstrap-lto. Thanks.

But Firefox doesn't build:

/home/trippels/gcc_test/usr/local/bin/c++ -fPIC -Wall -Wempty-body 
-Woverloaded-virtual -Wsign-compare -Wwrite-strings -Werror=endif-labels 
-Werror=int-to-pointer-cast -Werror=missing-braces -Werror=pointer-arith 
-Werror=return-type -Werror=sequence-point -Werror=unused-label 
-Werror=trigraphs -Werror=type-limits -Wno-invalid-offsetof -Wcast-align 
-flto=160 --param lto-partitions=160 -mcpu=power8 -ffunction-sections 
-fdata-sections -fno-exceptions -fno-strict-aliasing -frtti -fno-exceptions 
-fno-math-errno -std=gnu++0x -pthread -pipe -UDEBUG -DNDEBUG -O3 
-DU_STATIC_IMPLEMENTATION -fvisibility=hidden -W -Wall -pedantic 
-Wpointer-arith -Wwrite-strings -Wno-long-long -Wno-unused 
-Wno-unused-parameter   -lpthread 
-Wl,--hash-style=gnu,--as-needed,--gc-sections,--icf=all -Wl,-z,noexecstack 
-Wl,-z,text -Wl,--build-id -Wl,--gc-sections  -o ../../bin/makeconv makeconv.o 
ucnvstat.o genmbcs.o gencnvex.o -L../../lib -licutu -L../../lib -licui18n 
-L../../lib -licuuc -L../../stubdata -licudata -
l
pthread -ldl -lm
lto1: internal compiler error: in operator[], at vec.h:736
0x10122377 vec<int, va_heap, vl_embed>::operator[](unsigned int)
         ../../gcc/gcc/vec.h:736
0x10d1a0f3 vec<int, va_heap, vl_embed>::operator[](unsigned int)
         ../../gcc/gcc/ipa-icf.c:963
0x10d1a0f3 vec<int, va_heap, vl_ptr>::operator[](unsigned int)
         ../../gcc/gcc/vec.h:1202
0x10d1a0f3 ipa_icf::sem_function::bb_dict_test(auto_vec<int, 0ul>&, int, int)
         ../../gcc/gcc/ipa-icf.c:970
0x10d1aa73 ipa_icf::sem_function::equals_private(ipa_icf::sem_item*, 
hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&)
         ../../gcc/gcc/ipa-icf.c:512
0x10d1afb3 ipa_icf::sem_function::equals(ipa_icf::sem_item*, hash_map<symtab_node*, 
ipa_icf::sem_item*, default_hashmap_traits>&)
         ../../gcc/gcc/ipa-icf.c:384
0x10d1dba3 ipa_icf::sem_item_optimizer::subdivide_classes_by_equality(bool)
         ../../gcc/gcc/ipa-icf.c:1833
0x10d2397f ipa_icf::sem_item_optimizer::execute()
         ../../gcc/gcc/ipa-icf.c:1652
0x10d24a93 ipa_icf_driver
         ../../gcc/gcc/ipa-icf.c:2382
0x10d24a93 ipa_icf::pass_ipa_icf::execute(function*)
         ../../gcc/gcc/ipa-icf.c:2430
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: fatal error: /home/trippels/gcc_test/usr/local/bin/c++ returned 1 
exit status
compilation terminated.
/home/trippels/bin/ld: fatal error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[8]: *** [../../bin/makeconv] Error 1


Hi.

Well, this final version can run profiled-bootstrap and I capable of building 
FF with LTO.

Ready for trunk?
Thanks,
Martin
>From 630e42be0e3487aca012acbc03de64bfe0e53542 Mon Sep 17 00:00:00 2001
From: mliska <mli...@suse.cz>
Date: Tue, 25 Nov 2014 15:05:40 +0100
Subject: [PATCH] IPA ICF: fix memory leak.

gcc/ChangeLog:

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

	* ipa-icf.c (sem_function::equals_private): int* is replaced with
	auto_vec.
	(sem_function::bb_dict_test): Likewise.
	* ipa-icf.h: Likewise.
---
 gcc/ipa-icf.c | 16 ++++++++++------
 gcc/ipa-icf.h |  2 +-
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index e0633e7..3a5a40f 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 <int> 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<int> &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 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