diff mbox

[committed] Fix a memory leak in omp-low.c offloading

Message ID 20150316161732.GQ1746@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek March 16, 2015, 4:17 p.m. UTC
Hi!

While looking at PR65431, I've noticed we leak memory for every
expand_omp_target called.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk.

2015-03-16  Jakub Jelinek  <jakub@redhat.com>

	* omp-low.c (expand_omp_target): Use auto_vec<tree, 11>
	instead of vec<tree> * with vec_alloc and release for args.
	Adjust all users.


	Jakub
diff mbox

Patch

--- gcc/omp-low.c.jj	2015-03-16 10:47:40.000000000 +0100
+++ gcc/omp-low.c	2015-03-16 11:15:00.742111127 +0100
@@ -9105,14 +9105,11 @@  expand_omp_target (struct omp_region *re
     }
 
   gimple g;
-  vec<tree> *args;
   /* The maximum number used by any start_ix, without varargs.  */
-  unsigned int argcnt = 11;
-
-  vec_alloc (args, argcnt);
-  args->quick_push (device);
+  auto_vec<tree, 11> args;
+  args.quick_push (device);
   if (offloaded)
-    args->quick_push (build_fold_addr_expr (child_fn));
+    args.quick_push (build_fold_addr_expr (child_fn));
   switch (start_ix)
     {
     case BUILT_IN_GOMP_TARGET:
@@ -9120,7 +9117,7 @@  expand_omp_target (struct omp_region *re
     case BUILT_IN_GOMP_TARGET_UPDATE:
       /* This const void * is part of the current ABI, but we're not actually
 	 using it.  */
-      args->quick_push (build_zero_cst (ptr_type_node));
+      args.quick_push (build_zero_cst (ptr_type_node));
       break;
     case BUILT_IN_GOACC_DATA_START:
     case BUILT_IN_GOACC_ENTER_EXIT_DATA:
@@ -9130,10 +9127,10 @@  expand_omp_target (struct omp_region *re
     default:
       gcc_unreachable ();
     }
-  args->quick_push (t1);
-  args->quick_push (t2);
-  args->quick_push (t3);
-  args->quick_push (t4);
+  args.quick_push (t1);
+  args.quick_push (t2);
+  args.quick_push (t3);
+  args.quick_push (t4);
   switch (start_ix)
     {
     case BUILT_IN_GOACC_DATA_START:
@@ -9166,9 +9163,9 @@  expand_omp_target (struct omp_region *re
 	  t_vector_length = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
 					      integer_type_node,
 					      OMP_CLAUSE_VECTOR_LENGTH_EXPR (c));
-	args->quick_push (t_num_gangs);
-	args->quick_push (t_num_workers);
-	args->quick_push (t_vector_length);
+	args.quick_push (t_num_gangs);
+	args.quick_push (t_num_workers);
+	args.quick_push (t_vector_length);
       }
       /* FALLTHRU */
     case BUILT_IN_GOACC_ENTER_EXIT_DATA:
@@ -9190,13 +9187,13 @@  expand_omp_target (struct omp_region *re
 				      integer_type_node,
 				      OMP_CLAUSE_ASYNC_EXPR (c));
 
-	args->quick_push (t_async);
+	args.quick_push (t_async);
 	/* Save the index, and... */
-	t_wait_idx = args->length ();
+	t_wait_idx = args.length ();
 	/* ... push a default value.  */
-	args->quick_push (fold_convert_loc (gimple_location (entry_stmt),
-					    integer_type_node,
-					    integer_zero_node));
+	args.quick_push (fold_convert_loc (gimple_location (entry_stmt),
+					   integer_type_node,
+					   integer_zero_node));
 	c = find_omp_clause (clauses, OMP_CLAUSE_WAIT);
 	if (c)
 	  {
@@ -9206,19 +9203,19 @@  expand_omp_target (struct omp_region *re
 	      {
 		if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_WAIT)
 		  {
-		    args->safe_push (fold_convert_loc (OMP_CLAUSE_LOCATION (c),
-						       integer_type_node,
-						       OMP_CLAUSE_WAIT_EXPR (c)));
+		    args.safe_push (fold_convert_loc (OMP_CLAUSE_LOCATION (c),
+						      integer_type_node,
+						      OMP_CLAUSE_WAIT_EXPR (c)));
 		    n++;
 		  }
 	      }
 
 	    /* Now that we know the number, replace the default value.  */
-	    args->ordered_remove (t_wait_idx);
-	    args->quick_insert (t_wait_idx,
-				fold_convert_loc (gimple_location (entry_stmt),
-						  integer_type_node,
-						  build_int_cst (integer_type_node, n)));
+	    args.ordered_remove (t_wait_idx);
+	    args.quick_insert (t_wait_idx,
+			       fold_convert_loc (gimple_location (entry_stmt),
+						 integer_type_node,
+						 build_int_cst (integer_type_node, n)));
 	  }
       }
       break;
@@ -9226,8 +9223,7 @@  expand_omp_target (struct omp_region *re
       gcc_unreachable ();
     }
 
-  g = gimple_build_call_vec (builtin_decl_explicit (start_ix), *args);
-  args->release ();
+  g = gimple_build_call_vec (builtin_decl_explicit (start_ix), args);
   gimple_set_location (g, gimple_location (entry_stmt));
   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
   if (!offloaded)