Patchwork use VECs when parsing OpenMP for loops for C and C++

login
register
mail settings
Submitter Nathan Froyd
Date June 30, 2010, 1:33 a.m.
Message ID <20100630013344.GT22606@codesourcery.com>
Download mbox | patch
Permalink /patch/57347/
State New
Headers show

Comments

Nathan Froyd - June 30, 2010, 1:33 a.m.
This patch is the analogue of:

http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02766.html

only for the C and C++ front-ends.  Nothing too exciting.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

gcc/
	* c-parser.c (c_parser_omp_for_loop): Use a VEC for for_block.

gcc/cp/
	* parser.c (cp_parser_omp_for_loop): Use a VEC for for_block.
Diego Novillo - June 30, 2010, 11:52 a.m.
On Tue, Jun 29, 2010 at 21:33, Nathan Froyd <froydnj@codesourcery.com> wrote:

> gcc/
>        * c-parser.c (c_parser_omp_for_loop): Use a VEC for for_block.
>
> gcc/cp/
>        * parser.c (cp_parser_omp_for_loop): Use a VEC for for_block.

OK.

Diego.

Patch

diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index ac81d76..0493524 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -8150,10 +8150,11 @@  c_parser_omp_for_loop (location_t loc,
 		       c_parser *parser, tree clauses, tree *par_clauses)
 {
   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
-  tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
+  tree declv, condv, incrv, initv, ret = NULL;
   bool fail = false, open_brace_parsed = false;
   int i, collapse = 1, nbraces = 0;
   location_t for_loc;
+  VEC(tree,gc) *for_block = make_tree_vector ();
 
   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
@@ -8185,8 +8186,7 @@  c_parser_omp_for_loop (location_t loc,
       if (c_parser_next_token_starts_declaration (parser))
 	{
 	  if (i > 0)
-	    for_block
-	      = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
+	    VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
 	  c_parser_declaration_or_fndef (parser, true, true, true, true, true);
 	  decl = check_for_loop_decls (for_loc);
 	  if (decl == NULL)
@@ -8416,15 +8416,15 @@  c_parser_omp_for_loop (location_t loc,
       ret = stmt;
     }
 pop_scopes:
-  while (for_block)
+  while (!VEC_empty (tree, for_block))
     {
       /* FIXME diagnostics: LOC below should be the actual location of
 	 this particular for block.  We need to build a list of
 	 locations to go along with FOR_BLOCK.  */
-      stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true);
+      stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
       add_stmt (stmt);
-      for_block = TREE_CHAIN (for_block);
     }
+  release_tree_vector (for_block);
   return ret;
 }
 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4e4db2d..e8f10a4 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -22705,11 +22705,12 @@  static tree
 cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
 {
   tree init, cond, incr, body, decl, pre_body = NULL_TREE, ret;
-  tree for_block = NULL_TREE, real_decl, initv, condv, incrv, declv;
+  tree real_decl, initv, condv, incrv, declv;
   tree this_pre_body, cl;
   location_t loc_first;
   bool collapse_err = false;
   int i, collapse = 1, nbraces = 0;
+  VEC(tree,gc) *for_block = make_tree_vector ();
 
   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
@@ -22828,8 +22829,7 @@  cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
 				      LOOKUP_ONLYCONVERTING);
 		      if (CLASS_TYPE_P (TREE_TYPE (decl)))
 			{
-			  for_block
-			    = tree_cons (NULL, this_pre_body, for_block);
+			  VEC_safe_push (tree, gc, for_block, this_pre_body);
 			  init = NULL_TREE;
 			}
 		      else
@@ -23083,11 +23083,9 @@  cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
 	}
     }
 
-  while (for_block)
-    {
-      add_stmt (pop_stmt_list (TREE_VALUE (for_block)));
-      for_block = TREE_CHAIN (for_block);
-    }
+  while (!VEC_empty (tree, for_block))
+    add_stmt (pop_stmt_list (VEC_pop (tree, for_block)));
+  release_tree_vector (for_block);
 
   return ret;
 }