public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 3/9] Fix leak in gcc/tree-ssa-reassoc.c.
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
@ 2016-05-19 10:47 ` marxin
  2016-05-19 11:16   ` Richard Biener
  2016-05-19 10:47 ` [PATCH 1/9] Change ENABLE_VALGRIND_CHECKING to ENABLE_VALGRIND_ANNOTATIONS guard marxin
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

Leak can be seen e.g. here:
gcc reassoc-11.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -fdump-tree-reassoc1

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* tree-ssa-reassoc.c (eliminate_duplicate_pair): Truncate
	an auto_vec instead of re-creating it.
---
 gcc/tree-ssa-reassoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 3b5f36b..81b8977 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -732,7 +732,7 @@ eliminate_duplicate_pair (enum tree_code opcode,
 
 	  if (ops->length () == 2)
 	    {
-	      ops->create (0);
+	      ops->truncate (0);
 	      add_to_ops_vec (ops, build_zero_cst (TREE_TYPE (last->op)));
 	      *all_done = true;
 	    }
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 7/9] Fix memory leak in tree-if-conv.c
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
                   ` (3 preceding siblings ...)
  2016-05-19 10:47 ` [PATCH 5/9] Fix memory leak in tree-vect-slp.c marxin
@ 2016-05-19 10:47 ` marxin
  2016-05-19 11:16   ` Richard Biener
  2016-05-19 10:47 ` [PATCH 2/9] Fix leak in tree-ssa-loop-prefetch.c marxin
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

Leak can be seen e.g. here:
gcc i386/pr50482.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O3 -msse4

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* tree-if-conv.c (ifcvt_repair_bool_pattern): Utilize auto_vecs.
---
 gcc/tree-if-conv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index c38e21b..8dc9a43 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -2651,8 +2651,8 @@ ifcvt_repair_bool_pattern (basic_block bb)
   tree rhs;
   gimple *stmt;
   gimple_stmt_iterator gsi;
-  vec<gimple *> defuse_list = vNULL;
-  vec<gimple *> pattern_roots = vNULL;

+  auto_vec<gimple *> defuse_list;
+  auto_vec<gimple *> pattern_roots;
   bool repeat = true;
   int niter = 0;
   unsigned int ix;
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 5/9] Fix memory leak in tree-vect-slp.c
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
                   ` (2 preceding siblings ...)
  2016-05-19 10:47 ` [PATCH 8/9] Fix memory leak in tree-parloops.c marxin
@ 2016-05-19 10:47 ` marxin
  2016-05-19 11:15   ` Richard Biener
  2016-05-19 10:47 ` [PATCH 7/9] Fix memory leak in tree-if-conv.c marxin
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

Leak can be seen e.g. here:
gcc pr68817.f90 -fno-diagnostics-show-caret -fdiagnostics-color=never -O -O3 -ffast-math

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* tree-vect-slp.c (vect_attempt_slp_rearrange_stmts): Release
	bitmap.
---
 gcc/tree-vect-slp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index d713848..66db7d5 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -1308,7 +1308,10 @@ vect_attempt_slp_rearrange_stmts (slp_instance slp_instn)
   FOR_EACH_VEC_ELT (node->load_permutation, i, lidx)
     {
       if (lidx >= group_size)
-	return false;
+	{
+	  sbitmap_free (load_index);
+	  return false;
+	}
       if (bitmap_bit_p (load_index, lidx))
 	{
 	  sbitmap_free (load_index);
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 2/9] Fix leak in tree-ssa-loop-prefetch.c
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
                   ` (4 preceding siblings ...)
  2016-05-19 10:47 ` [PATCH 7/9] Fix memory leak in tree-if-conv.c marxin
@ 2016-05-19 10:47 ` marxin
  2016-05-19 11:16   ` Richard Biener
  2016-05-19 10:47 ` [PATCH 4/9] Fix memory leak in omp-simd-clone.c marxin
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

This fixes memory leak which can be e.g. for
20020122-2.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -fprefetch-loop-arrays.

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* tree-ssa-loop-prefetch.c (determine_loop_nest_reuse): Use
	auto_vec instead of vec.
---
 gcc/tree-ssa-loop-prefetch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c
index c054c60..49fd597 100644
--- a/gcc/tree-ssa-loop-prefetch.c
+++ b/gcc/tree-ssa-loop-prefetch.c
@@ -1546,7 +1546,7 @@ determine_loop_nest_reuse (struct loop *loop, struct mem_ref_group *refs,
   vec<ddr_p> dependences = vNULL;
   struct mem_ref_group *gr;
   struct mem_ref *ref, *refb;
-  vec<loop_p> vloops = vNULL;
+  auto_vec<loop_p> vloops;
   unsigned *loop_data_size;
   unsigned i, j, n;
   unsigned volume, dist, adist;
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 0/9] Remove various memory leaks
@ 2016-05-19 10:47 marxin
  2016-05-19 10:47 ` [PATCH 3/9] Fix leak in gcc/tree-ssa-reassoc.c marxin
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

Hello.

Following patchset removes bunch of memory leaks that are connect
to middle-end of the compiler.

Each patch contains corresponding ChangeLog entry and link to a source file
in our test-suite which suffers from a memory leak.

The patchset has been tested in whole on x86_64-linux-gnu and does not
introduce any new regression.

Ready to be installed?
Thanks,
Martin

marxin (9):
  Change ENABLE_VALGRIND_CHECKING to ENABLE_VALGRIND_ANNOTATIONS guard.
  Fix leak in tree-ssa-loop-prefetch.c
  Fix leak in gcc/tree-ssa-reassoc.c.
  Fix memory leak in omp-simd-clone.c
  Fix memory leak in tree-vect-slp.c
  Fix memory leak in ipa-pure-const
  Fix memory leak in tree-if-conv.c
  Fix memory leak in tree-parloops.c
  Fix memory leak in tree-vect-stmts.c

 gcc/ipa-pure-const.c         | 14 ++++++++------
 gcc/omp-simd-clone.c         |  1 +
 gcc/tree-if-conv.c           |  4 ++--
 gcc/tree-parloops.c          |  1 +
 gcc/tree-ssa-loop-prefetch.c |  2 +-
 gcc/tree-ssa-reassoc.c       |  2 +-
 gcc/tree-vect-slp.c          |  5 ++++-
 gcc/tree-vect-stmts.c        | 21 +++++----------------
 libcpp/config.in             |  3 +++
 libcpp/configure             | 22 ++++++++++++++++++++++
 libcpp/configure.ac          | 15 +++++++++++++++
 libcpp/lex.c                 |  4 ++--
 12 files changed, 65 insertions(+), 29 deletions(-)

-- 
2.8.2

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 8/9] Fix memory leak in tree-parloops.c
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
  2016-05-19 10:47 ` [PATCH 3/9] Fix leak in gcc/tree-ssa-reassoc.c marxin
  2016-05-19 10:47 ` [PATCH 1/9] Change ENABLE_VALGRIND_CHECKING to ENABLE_VALGRIND_ANNOTATIONS guard marxin
@ 2016-05-19 10:47 ` marxin
  2016-05-19 11:17   ` Richard Biener
  2016-05-19 10:47 ` [PATCH 5/9] Fix memory leak in tree-vect-slp.c marxin
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

The leak can be seen here:
gcc kernels-counter-vars-function-scope.c -fno-diagnostics-show-caret \
-fdiagnostics-color=never -fopenacc -O2 -fdump-tree-parloops1-all

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* tree-parloops.c (oacc_entry_exit_ok): Release a vector.
---
 gcc/tree-parloops.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 25a29bd..f472717 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -3168,6 +3168,7 @@ oacc_entry_exit_ok (struct loop *loop,
 	}
     }
 
+  region_bbs.release ();
   free (loop_bbs);
 
   BITMAP_FREE (in_loop_bbs);
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 4/9] Fix memory leak in omp-simd-clone.c
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
                   ` (5 preceding siblings ...)
  2016-05-19 10:47 ` [PATCH 2/9] Fix leak in tree-ssa-loop-prefetch.c marxin
@ 2016-05-19 10:47 ` marxin
  2016-05-19 10:50   ` Jakub Jelinek
  2016-05-19 11:03 ` [PATCH 9/9] Fix memory leak in tree-vect-stmts.c marxin
  2016-05-19 11:05 ` [PATCH 6/9] Fix memory leak in ipa-pure-const marxin
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

Leak can be seen e.g. here:
gcc pr68339.c -fno-diagnostics-show-caret -fdiagnostics-color=never --param ggc-min-heapsize=0 --param ggc-min-expand=0 -fopenmp-simd

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* omp-simd-clone.c (simd_clone_adjust): Release vector.
---
 gcc/omp-simd-clone.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
index fa6ffec..ad7e83b 100644
--- a/gcc/omp-simd-clone.c
+++ b/gcc/omp-simd-clone.c
@@ -1079,6 +1079,7 @@ simd_clone_adjust (struct cgraph_node *node)
   tree iter1 = make_ssa_name (iter);
   tree iter2 = make_ssa_name (iter);
   ipa_simd_modify_function_body (node, adjustments, retval, iter1);
+  adjustments.release ();
 
   /* Initialize the iteration variable.  */
   basic_block entry_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/9] Change ENABLE_VALGRIND_CHECKING to ENABLE_VALGRIND_ANNOTATIONS guard.
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
  2016-05-19 10:47 ` [PATCH 3/9] Fix leak in gcc/tree-ssa-reassoc.c marxin
@ 2016-05-19 10:47 ` marxin
  2016-05-19 18:41   ` Jeff Law
  2016-05-19 10:47 ` [PATCH 8/9] Fix memory leak in tree-parloops.c marxin
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 10:47 UTC (permalink / raw)
  To: gcc-patches

Following change is very similar to what I did in:
https://gcc.gnu.org/ml/gcc-patches/2016-01/msg02103.html

It's more logical to encapsulate valgrind annotation magic within
a ENABLE_VALGRIND_ANNOTATIONS macro rather than ENABLE_VALGRIND_CHECKING.

libcpp/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* config.in: Regenerated.
	* configure: Likewise.
	* configure.ac: Handle --enable-valgrind-annotations.
	* lex.c (new_buff): Use ENABLE_VALGRIND_ANNOTATIONS instead
	of ENABLE_VALGRIND_CHECKING.
	(_cpp_free_buff): Likewise.
---
 libcpp/config.in    |  3 +++
 libcpp/configure    | 22 ++++++++++++++++++++++

 libcpp/configure.ac | 15 +++++++++++++++
 libcpp/lex.c        |  4 ++--
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/libcpp/config.in b/libcpp/config.in
index e02ac5e..3bbffe7 100644
--- a/libcpp/config.in
+++ b/libcpp/config.in
@@ -21,6 +21,9 @@
    language is requested. */
 #undef ENABLE_NLS
 
+/* Define to get calls to the valgrind runtime enabled. */
+#undef ENABLE_VALGRIND_ANNOTATIONS
+
 /* Define if you want to workaround valgrind (a memory checker) warnings about
    possible memory leaks because of libcpp use of interior pointers. */
 #undef ENABLE_VALGRIND_CHECKING
diff --git a/libcpp/configure b/libcpp/configure
index 0342f16..b6f129c 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -703,6 +703,7 @@ enable_maintainer_mode
 enable_checking
 enable_canonical_system_headers
 enable_host_shared
+enable_valgrind_annotations
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1343,6 +1344,8 @@ Optional Features:
   --enable-canonical-system-headers
                           enable or disable system headers canonicalization
   --enable-host-shared    build host code as shared libraries
+  --enable-valgrind-annotations
+                          enable valgrind runtime interaction
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -7355,6 +7358,25 @@ fi
 
 
 
+# Check whether --enable-valgrind-annotations was given.
+if test "${enable_valgrind_annotations+set}" = set; then :
+  enableval=$enable_valgrind_annotations;
+else
+  enable_valgrind_annotations=no
+fi
+
+if test x$enable_valgrind_annotations != xno \
+    || test x$ac_valgrind_checking != x; then
+  if (test $have_valgrind_h = no \
+      && test $gcc_cv_header_memcheck_h = no \
+      && test $gcc_cv_header_valgrind_memcheck_h = no); then
+    as_fn_error "*** Can't find valgrind/memcheck.h, memcheck.h or valgrind.h" "$LINENO" 5
+  fi
+
+$as_echo "#define ENABLE_VALGRIND_ANNOTATIONS 1" >>confdefs.h
+
+fi
+
 # Output.
 
 ac_config_headers="$ac_config_headers config.h:config.in"
diff --git a/libcpp/configure.ac b/libcpp/configure.ac
index 0005c58..3077ee0 100644
--- a/libcpp/configure.ac
+++ b/libcpp/configure.ac
@@ -200,6 +200,21 @@ AC_ARG_ENABLE(host-shared,
 [PICFLAG=-fPIC], [PICFLAG=])
 AC_SUBST(PICFLAG)
 
+AC_ARG_ENABLE(valgrind-annotations,
+[AS_HELP_STRING([--enable-valgrind-annotations],
+		[enable valgrind runtime interaction])], [],
+[enable_valgrind_annotations=no])
+if test x$enable_valgrind_annotations != xno \
+    || test x$ac_valgrind_checking != x; then
+  if (test $have_valgrind_h = no \
+      && test $gcc_cv_header_memcheck_h = no \
+      && test $gcc_cv_header_valgrind_memcheck_h = no); then
+    AC_MSG_ERROR([*** Can't find valgrind/memcheck.h, memcheck.h or valgrind.h])
+  fi
+  AC_DEFINE(ENABLE_VALGRIND_ANNOTATIONS, 1,
+[Define to get calls to the valgrind runtime enabled.])
+fi
+
 # Output.
 
 AC_CONFIG_HEADERS(config.h:config.in, [echo timestamp > stamp-h1])
diff --git a/libcpp/lex.c b/libcpp/lex.c
index e5a0397..236418d 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -3147,7 +3147,7 @@ new_buff (size_t len)
     len = MIN_BUFF_SIZE;
   len = CPP_ALIGN (len);
 
-#ifdef ENABLE_VALGRIND_CHECKING
+#ifdef ENABLE_VALGRIND_ANNOTATIONS
   /* Valgrind warns about uses of interior pointers, so put _cpp_buff
      struct first.  */
   size_t slen = CPP_ALIGN2 (sizeof (_cpp_buff), 2 * DEFAULT_ALIGNMENT);
@@ -3244,7 +3244,7 @@ _cpp_free_buff (_cpp_buff *buff)
   for (; buff; buff = next)
     {
       next = buff->next;
-#ifdef ENABLE_VALGRIND_CHECKING
+#ifdef ENABLE_VALGRIND_ANNOTATIONS
       free (buff);
 #else
       free (buff->base);
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/9] Fix memory leak in omp-simd-clone.c
  2016-05-19 10:47 ` [PATCH 4/9] Fix memory leak in omp-simd-clone.c marxin
@ 2016-05-19 10:50   ` Jakub Jelinek
  0 siblings, 0 replies; 19+ messages in thread
From: Jakub Jelinek @ 2016-05-19 10:50 UTC (permalink / raw)
  To: marxin; +Cc: gcc-patches

On Thu, May 19, 2016 at 12:44:10PM +0200, marxin wrote:
> Leak can be seen e.g. here:
> gcc pr68339.c -fno-diagnostics-show-caret -fdiagnostics-color=never --param ggc-min-heapsize=0 --param ggc-min-expand=0 -fopenmp-simd
> 
> gcc/ChangeLog:
> 
> 2016-05-18  Martin Liska  <mliska@suse.cz>
> 
> 	* omp-simd-clone.c (simd_clone_adjust): Release vector.

Ok, thanks.

> --- a/gcc/omp-simd-clone.c
> +++ b/gcc/omp-simd-clone.c
> @@ -1079,6 +1079,7 @@ simd_clone_adjust (struct cgraph_node *node)
>    tree iter1 = make_ssa_name (iter);
>    tree iter2 = make_ssa_name (iter);
>    ipa_simd_modify_function_body (node, adjustments, retval, iter1);
> +  adjustments.release ();
>  
>    /* Initialize the iteration variable.  */
>    basic_block entry_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
> -- 
> 2.8.2
> 

	Jakub

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 9/9] Fix memory leak in tree-vect-stmts.c
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
                   ` (6 preceding siblings ...)
  2016-05-19 10:47 ` [PATCH 4/9] Fix memory leak in omp-simd-clone.c marxin
@ 2016-05-19 11:03 ` marxin
  2016-05-19 11:17   ` Richard Biener
  2016-05-19 11:05 ` [PATCH 6/9] Fix memory leak in ipa-pure-const marxin
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 11:03 UTC (permalink / raw)
  To: gcc-patches

The leak can be seen here:
gcc pr60823-2.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 \
-fopenmp-simd

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* tree-vect-stmts.c (vectorizable_simd_clone_call): Utilize
	auto_vec instead of vec.
---
 gcc/tree-vect-stmts.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 9ab4af4..3bcd0ce 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -2755,7 +2755,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
   gimple *def_stmt;
   gimple *new_stmt = NULL;
   int ncopies, j;
-  vec<simd_call_arg_info> arginfo = vNULL;
+  auto_vec<simd_call_arg_info> arginfo;
   vec<tree> vargs = vNULL;
   size_t i, nargs;
   tree lhs, rtype, ratype;
@@ -2802,7 +2802,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
   if (nargs == 0)
     return false;
 
-  arginfo.create (nargs);
+  arginfo.reserve (nargs, true);
 
   for (i = 0; i < nargs; i++)
     {
@@ -2822,7 +2822,6 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
 	  if (dump_enabled_p ())
 	    dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
 			     "use not simple.\n");
-	  arginfo.release ();
 	  return false;
 	}
 
@@ -2978,10 +2977,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
       }
 
   if (bestn == NULL)
-    {
-      arginfo.release ();
-      return false;
-    }
+    return false;
 
   for (i = 0; i < nargs; i++)
     if ((arginfo[i].dt == vect_constant_def
@@ -2994,10 +2990,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
 	if (arginfo[i].vectype == NULL
 	    || (TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)
 		> bestn->simdclone->simdlen))
-	  {
-	    arginfo.release ();
-	    return false;
-	  }
+	  return false;
       }
 
   fndecl = bestn->decl;
@@ -3009,10 +3002,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
      performed using SIMD instructions.  */
   if ((loop == NULL || (unsigned) loop->safelen < nunits)
       && gimple_vuse (stmt))
-    {
-      arginfo.release ();
-      return false;
-    }
+    return false;
 
   /* Sanity check: make sure that at least one copy of the vectorized stmt
      needs to be generated.  */
@@ -3041,7 +3031,6 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
 	dump_printf_loc (MSG_NOTE, vect_location,
 			 "=== vectorizable_simd_clone_call ===\n");
 /*      vect_model_simple_cost (stmt_info, ncopies, dt, NULL, NULL); */
-      arginfo.release ();
       return true;
     }
 
-- 
2.8.2

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 6/9] Fix memory leak in ipa-pure-const
  2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
                   ` (7 preceding siblings ...)
  2016-05-19 11:03 ` [PATCH 9/9] Fix memory leak in tree-vect-stmts.c marxin
@ 2016-05-19 11:05 ` marxin
  2016-05-19 11:18   ` Richard Biener
  8 siblings, 1 reply; 19+ messages in thread
From: marxin @ 2016-05-19 11:05 UTC (permalink / raw)
  To: gcc-patches

Leak can be seen e.g. here:
gcc i386/mvc6.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O3

gcc/ChangeLog:

2016-05-18  Martin Liska  <mliska@suse.cz>

	* ipa-pure-const.c (set_function_state): Remove an existing
	funct_state.
	(remove_node_data): Do not free it as it's released
	in set_function_state.
---
 gcc/ipa-pure-const.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index ba76275..a9570e4 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -258,6 +258,13 @@ set_function_state (struct cgraph_node *node, funct_state s)
   if (!funct_state_vec.exists ()
       || funct_state_vec.length () <= (unsigned int)node->uid)
      funct_state_vec.safe_grow_cleared (node->uid + 1);
+
+  /* If funct_state_vec already contains a funct_state, we have to release
+     it before it's going to be ovewritten.  */
+  if (funct_state_vec[node->uid] != NULL
+      && funct_state_vec[node->uid] != &varying_state)
+    free (funct_state_vec[node->uid]);
+
   funct_state_vec[node->uid] = s;
 }
 
@@ -956,12 +963,7 @@ static void
 remove_node_data (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
 {
   if (has_function_state (node))
-    {
-      funct_state l = get_function_state (node);
-      if (l != &varying_state)
-        free (l);
-      set_function_state (node, NULL);
-    }
+    set_function_state (node, NULL);
 }
 
 \f
-- 
2.8.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 5/9] Fix memory leak in tree-vect-slp.c
  2016-05-19 10:47 ` [PATCH 5/9] Fix memory leak in tree-vect-slp.c marxin
@ 2016-05-19 11:15   ` Richard Biener
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Biener @ 2016-05-19 11:15 UTC (permalink / raw)
  To: marxin; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:44 PM, marxin <mliska@suse.cz> wrote:
> Leak can be seen e.g. here:
> gcc pr68817.f90 -fno-diagnostics-show-caret -fdiagnostics-color=never -O -O3 -ffast-math

Ok for trunk and branches.

Richard.

> gcc/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
>         * tree-vect-slp.c (vect_attempt_slp_rearrange_stmts): Release
>         bitmap.
> ---
>  gcc/tree-vect-slp.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
> index d713848..66db7d5 100644
> --- a/gcc/tree-vect-slp.c
> +++ b/gcc/tree-vect-slp.c
> @@ -1308,7 +1308,10 @@ vect_attempt_slp_rearrange_stmts (slp_instance slp_instn)
>    FOR_EACH_VEC_ELT (node->load_permutation, i, lidx)
>      {
>        if (lidx >= group_size)
> -       return false;
> +       {
> +         sbitmap_free (load_index);
> +         return false;
> +       }
>        if (bitmap_bit_p (load_index, lidx))
>         {
>           sbitmap_free (load_index);
> --
> 2.8.2
>
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/9] Fix leak in gcc/tree-ssa-reassoc.c.
  2016-05-19 10:47 ` [PATCH 3/9] Fix leak in gcc/tree-ssa-reassoc.c marxin
@ 2016-05-19 11:16   ` Richard Biener
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Biener @ 2016-05-19 11:16 UTC (permalink / raw)
  To: marxin; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:44 PM, marxin <mliska@suse.cz> wrote:
> Leak can be seen e.g. here:
> gcc reassoc-11.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -fdump-tree-reassoc1

Ok.

Richard.

> gcc/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
>         * tree-ssa-reassoc.c (eliminate_duplicate_pair): Truncate
>         an auto_vec instead of re-creating it.
> ---
>  gcc/tree-ssa-reassoc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
> index 3b5f36b..81b8977 100644
> --- a/gcc/tree-ssa-reassoc.c
> +++ b/gcc/tree-ssa-reassoc.c
> @@ -732,7 +732,7 @@ eliminate_duplicate_pair (enum tree_code opcode,
>
>           if (ops->length () == 2)
>             {
> -             ops->create (0);
> +             ops->truncate (0);
>               add_to_ops_vec (ops, build_zero_cst (TREE_TYPE (last->op)));
>               *all_done = true;
>             }
> --
> 2.8.2
>
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 7/9] Fix memory leak in tree-if-conv.c
  2016-05-19 10:47 ` [PATCH 7/9] Fix memory leak in tree-if-conv.c marxin
@ 2016-05-19 11:16   ` Richard Biener
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Biener @ 2016-05-19 11:16 UTC (permalink / raw)
  To: marxin; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:44 PM, marxin <mliska@suse.cz> wrote:
> Leak can be seen e.g. here:
> gcc i386/pr50482.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O3 -msse4

Ok.

Richard.

> gcc/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
>         * tree-if-conv.c (ifcvt_repair_bool_pattern): Utilize auto_vecs.
> ---
>  gcc/tree-if-conv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
> index c38e21b..8dc9a43 100644
> --- a/gcc/tree-if-conv.c
> +++ b/gcc/tree-if-conv.c
> @@ -2651,8 +2651,8 @@ ifcvt_repair_bool_pattern (basic_block bb)
>    tree rhs;
>    gimple *stmt;
>    gimple_stmt_iterator gsi;
> -  vec<gimple *> defuse_list = vNULL;
> -  vec<gimple *> pattern_roots = vNULL;
>
> +  auto_vec<gimple *> defuse_list;
> +  auto_vec<gimple *> pattern_roots;
>    bool repeat = true;
>    int niter = 0;
>    unsigned int ix;
> --
> 2.8.2
>
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/9] Fix leak in tree-ssa-loop-prefetch.c
  2016-05-19 10:47 ` [PATCH 2/9] Fix leak in tree-ssa-loop-prefetch.c marxin
@ 2016-05-19 11:16   ` Richard Biener
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Biener @ 2016-05-19 11:16 UTC (permalink / raw)
  To: marxin; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:44 PM, marxin <mliska@suse.cz> wrote:
> This fixes memory leak which can be e.g. for
> 20020122-2.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -fprefetch-loop-arrays.

Ok.

Richard.

> gcc/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
>         * tree-ssa-loop-prefetch.c (determine_loop_nest_reuse): Use
>         auto_vec instead of vec.
> ---
>  gcc/tree-ssa-loop-prefetch.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c
> index c054c60..49fd597 100644
> --- a/gcc/tree-ssa-loop-prefetch.c
> +++ b/gcc/tree-ssa-loop-prefetch.c
> @@ -1546,7 +1546,7 @@ determine_loop_nest_reuse (struct loop *loop, struct mem_ref_group *refs,
>    vec<ddr_p> dependences = vNULL;
>    struct mem_ref_group *gr;
>    struct mem_ref *ref, *refb;
> -  vec<loop_p> vloops = vNULL;
> +  auto_vec<loop_p> vloops;
>    unsigned *loop_data_size;
>    unsigned i, j, n;
>    unsigned volume, dist, adist;
> --
> 2.8.2
>
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 8/9] Fix memory leak in tree-parloops.c
  2016-05-19 10:47 ` [PATCH 8/9] Fix memory leak in tree-parloops.c marxin
@ 2016-05-19 11:17   ` Richard Biener
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Biener @ 2016-05-19 11:17 UTC (permalink / raw)
  To: marxin; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:44 PM, marxin <mliska@suse.cz> wrote:
> The leak can be seen here:
> gcc kernels-counter-vars-function-scope.c -fno-diagnostics-show-caret \
> -fdiagnostics-color=never -fopenacc -O2 -fdump-tree-parloops1-all

Ok.

Richard.

> gcc/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
>         * tree-parloops.c (oacc_entry_exit_ok): Release a vector.
> ---
>  gcc/tree-parloops.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
> index 25a29bd..f472717 100644
> --- a/gcc/tree-parloops.c
> +++ b/gcc/tree-parloops.c
> @@ -3168,6 +3168,7 @@ oacc_entry_exit_ok (struct loop *loop,
>         }
>      }
>
> +  region_bbs.release ();
>    free (loop_bbs);
>
>    BITMAP_FREE (in_loop_bbs);
> --
> 2.8.2
>
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 9/9] Fix memory leak in tree-vect-stmts.c
  2016-05-19 11:03 ` [PATCH 9/9] Fix memory leak in tree-vect-stmts.c marxin
@ 2016-05-19 11:17   ` Richard Biener
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Biener @ 2016-05-19 11:17 UTC (permalink / raw)
  To: marxin; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:44 PM, marxin <mliska@suse.cz> wrote:
> The leak can be seen here:
> gcc pr60823-2.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 \
> -fopenmp-simd

Ok.

Richard.

> gcc/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
>         * tree-vect-stmts.c (vectorizable_simd_clone_call): Utilize
>         auto_vec instead of vec.
> ---
>  gcc/tree-vect-stmts.c | 21 +++++----------------
>  1 file changed, 5 insertions(+), 16 deletions(-)
>
> diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
> index 9ab4af4..3bcd0ce 100644
> --- a/gcc/tree-vect-stmts.c
> +++ b/gcc/tree-vect-stmts.c
> @@ -2755,7 +2755,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
>    gimple *def_stmt;
>    gimple *new_stmt = NULL;
>    int ncopies, j;
> -  vec<simd_call_arg_info> arginfo = vNULL;
> +  auto_vec<simd_call_arg_info> arginfo;
>    vec<tree> vargs = vNULL;
>    size_t i, nargs;
>    tree lhs, rtype, ratype;
> @@ -2802,7 +2802,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
>    if (nargs == 0)
>      return false;
>
> -  arginfo.create (nargs);
> +  arginfo.reserve (nargs, true);
>
>    for (i = 0; i < nargs; i++)
>      {
> @@ -2822,7 +2822,6 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
>           if (dump_enabled_p ())
>             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
>                              "use not simple.\n");
> -         arginfo.release ();
>           return false;
>         }
>
> @@ -2978,10 +2977,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
>        }
>
>    if (bestn == NULL)
> -    {
> -      arginfo.release ();
> -      return false;
> -    }
> +    return false;
>
>    for (i = 0; i < nargs; i++)
>      if ((arginfo[i].dt == vect_constant_def
> @@ -2994,10 +2990,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
>         if (arginfo[i].vectype == NULL
>             || (TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)
>                 > bestn->simdclone->simdlen))
> -         {
> -           arginfo.release ();
> -           return false;
> -         }
> +         return false;
>        }
>
>    fndecl = bestn->decl;
> @@ -3009,10 +3002,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
>       performed using SIMD instructions.  */
>    if ((loop == NULL || (unsigned) loop->safelen < nunits)
>        && gimple_vuse (stmt))
> -    {
> -      arginfo.release ();
> -      return false;
> -    }
> +    return false;
>
>    /* Sanity check: make sure that at least one copy of the vectorized stmt
>       needs to be generated.  */
> @@ -3041,7 +3031,6 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
>         dump_printf_loc (MSG_NOTE, vect_location,
>                          "=== vectorizable_simd_clone_call ===\n");
>  /*      vect_model_simple_cost (stmt_info, ncopies, dt, NULL, NULL); */
> -      arginfo.release ();
>        return true;
>      }
>
> --
> 2.8.2
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 6/9] Fix memory leak in ipa-pure-const
  2016-05-19 11:05 ` [PATCH 6/9] Fix memory leak in ipa-pure-const marxin
@ 2016-05-19 11:18   ` Richard Biener
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Biener @ 2016-05-19 11:18 UTC (permalink / raw)
  To: marxin; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:44 PM, marxin <mliska@suse.cz> wrote:
> Leak can be seen e.g. here:
> gcc i386/mvc6.c -fno-diagnostics-show-caret -fdiagnostics-color=never -O3

Ok.

Richard.

> gcc/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
>         * ipa-pure-const.c (set_function_state): Remove an existing
>         funct_state.
>         (remove_node_data): Do not free it as it's released
>         in set_function_state.
> ---
>  gcc/ipa-pure-const.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
> index ba76275..a9570e4 100644
> --- a/gcc/ipa-pure-const.c
> +++ b/gcc/ipa-pure-const.c
> @@ -258,6 +258,13 @@ set_function_state (struct cgraph_node *node, funct_state s)
>    if (!funct_state_vec.exists ()
>        || funct_state_vec.length () <= (unsigned int)node->uid)
>       funct_state_vec.safe_grow_cleared (node->uid + 1);
> +
> +  /* If funct_state_vec already contains a funct_state, we have to release
> +     it before it's going to be ovewritten.  */
> +  if (funct_state_vec[node->uid] != NULL
> +      && funct_state_vec[node->uid] != &varying_state)
> +    free (funct_state_vec[node->uid]);
> +
>    funct_state_vec[node->uid] = s;
>  }
>
> @@ -956,12 +963,7 @@ static void
>  remove_node_data (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
>  {
>    if (has_function_state (node))
> -    {
> -      funct_state l = get_function_state (node);
> -      if (l != &varying_state)
> -        free (l);
> -      set_function_state (node, NULL);
> -    }
> +    set_function_state (node, NULL);
>  }
>
>
> --
> 2.8.2
>
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/9] Change ENABLE_VALGRIND_CHECKING to ENABLE_VALGRIND_ANNOTATIONS guard.
  2016-05-19 10:47 ` [PATCH 1/9] Change ENABLE_VALGRIND_CHECKING to ENABLE_VALGRIND_ANNOTATIONS guard marxin
@ 2016-05-19 18:41   ` Jeff Law
  0 siblings, 0 replies; 19+ messages in thread
From: Jeff Law @ 2016-05-19 18:41 UTC (permalink / raw)
  To: marxin, gcc-patches

On 05/19/2016 04:43 AM, marxin wrote:
> Following change is very similar to what I did in:
> https://gcc.gnu.org/ml/gcc-patches/2016-01/msg02103.html
>
> It's more logical to encapsulate valgrind annotation magic within
> a ENABLE_VALGRIND_ANNOTATIONS macro rather than ENABLE_VALGRIND_CHECKING.
>
> libcpp/ChangeLog:
>
> 2016-05-18  Martin Liska  <mliska@suse.cz>
>
> 	* config.in: Regenerated.
> 	* configure: Likewise.
> 	* configure.ac: Handle --enable-valgrind-annotations.
> 	* lex.c (new_buff): Use ENABLE_VALGRIND_ANNOTATIONS instead
> 	of ENABLE_VALGRIND_CHECKING.
> 	(_cpp_free_buff): Likewise.
OK.
jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2016-05-19 18:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-19 10:47 [PATCH 0/9] Remove various memory leaks marxin
2016-05-19 10:47 ` [PATCH 3/9] Fix leak in gcc/tree-ssa-reassoc.c marxin
2016-05-19 11:16   ` Richard Biener
2016-05-19 10:47 ` [PATCH 1/9] Change ENABLE_VALGRIND_CHECKING to ENABLE_VALGRIND_ANNOTATIONS guard marxin
2016-05-19 18:41   ` Jeff Law
2016-05-19 10:47 ` [PATCH 8/9] Fix memory leak in tree-parloops.c marxin
2016-05-19 11:17   ` Richard Biener
2016-05-19 10:47 ` [PATCH 5/9] Fix memory leak in tree-vect-slp.c marxin
2016-05-19 11:15   ` Richard Biener
2016-05-19 10:47 ` [PATCH 7/9] Fix memory leak in tree-if-conv.c marxin
2016-05-19 11:16   ` Richard Biener
2016-05-19 10:47 ` [PATCH 2/9] Fix leak in tree-ssa-loop-prefetch.c marxin
2016-05-19 11:16   ` Richard Biener
2016-05-19 10:47 ` [PATCH 4/9] Fix memory leak in omp-simd-clone.c marxin
2016-05-19 10:50   ` Jakub Jelinek
2016-05-19 11:03 ` [PATCH 9/9] Fix memory leak in tree-vect-stmts.c marxin
2016-05-19 11:17   ` Richard Biener
2016-05-19 11:05 ` [PATCH 6/9] Fix memory leak in ipa-pure-const marxin
2016-05-19 11:18   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).