[committed] c: Rewrite c_parser_omp_tile_sizes to use c_parser_expr_list

Message ID Zoz9n9VYbkDKGhxv@tucnak
State New
Headers
Series [committed] c: Rewrite c_parser_omp_tile_sizes to use c_parser_expr_list |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_check--master-arm fail Patch failed to apply

Commit Message

Jakub Jelinek July 9, 2024, 9:06 a.m. UTC
  Hi!

The following patch simplifies c_parser_omp_tile_sizes to use
c_parser_expr_list, so that it will get CPP_EMBED parsing naturally,
without having another spot that needs to be adjusted for it.

Tested on x86_64-linux, committed to trunk.

2024-07-09  Jakub Jelinek  <jakub@redhat.com>

	* c-parser.cc (c_parser_omp_tile_sizes): Use c_parser_expr_list.

	* c-c++-common/gomp/tile-11.c: Adjust expected diagnostics for c.
	* c-c++-common/gomp/tile-12.c: Likewise.


	Jakub
  

Patch

--- gcc/c/c-parser.cc.jj	2024-07-02 15:07:55.091914989 +0200
+++ gcc/c/c-parser.cc	2024-07-09 10:12:16.767356910 +0200
@@ -26431,24 +26431,20 @@  c_parser_omp_tile_sizes (c_parser *parse
   if (!parens.require_open (parser))
     return error_mark_node;
 
-  do
-    {
-      if (sizes && !c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
-	return error_mark_node;
-
-      location_t expr_loc = c_parser_peek_token (parser)->location;
-      c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
-      cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
-      tree expr = cexpr.value;
+  vec<tree, va_gc> *sizes_vec
+    = c_parser_expr_list (parser, true, true, NULL, NULL, NULL, NULL);
+  sizes = build_tree_list_vec (sizes_vec);
+  release_tree_vector (sizes_vec);
 
+  for (tree s = sizes; s; s = TREE_CHAIN (s))
+    {
+      tree expr = TREE_VALUE (s);
       if (expr == error_mark_node)
 	{
 	  parens.skip_until_found_close (parser);
 	  return error_mark_node;
 	}
 
-      expr = c_fully_fold (expr, false, NULL);
-
       HOST_WIDE_INT n;
       if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
 	  || !tree_fits_shwi_p (expr)
@@ -26457,17 +26453,14 @@  c_parser_omp_tile_sizes (c_parser *parse
 	{
 	  c_parser_error (parser, "%<sizes%> argument needs positive"
 				  " integral constant");
-	  expr = integer_one_node;
+	  TREE_VALUE (s) = integer_one_node;
 	}
-
-      sizes = tree_cons (NULL_TREE, expr, sizes);
     }
-  while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN));
   parens.require_close (parser);
 
   gcc_assert (sizes);
   tree c = build_omp_clause (loc, OMP_CLAUSE_SIZES);
-  OMP_CLAUSE_SIZES_LIST (c) = nreverse (sizes);
+  OMP_CLAUSE_SIZES_LIST (c) = sizes;
 
   return c;
 }
--- gcc/testsuite/c-c++-common/gomp/tile-11.c.jj	2024-06-06 22:11:22.860432400 +0200
+++ gcc/testsuite/c-c++-common/gomp/tile-11.c	2024-07-09 10:19:50.625346103 +0200
@@ -21,9 +21,9 @@  test (void)
   for (int i = 0; i < 100; ++i)
     dummy (i);
 
-  #pragma omp tile sizes(1,2 /* { dg-error "expected ',' before end of line" } */
-  for (int i = 0; i < 100; ++i)
-    dummy (i);
+  #pragma omp tile sizes(1,2 /* { dg-error "expected '\\\)' before end of line" "" { target c } } */
+  for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" "" { target c } } */
+    dummy (i); /* { dg-error "expected ',' before end of line" "" { target c++ } .-2 } */
 
   #pragma omp tile sizes /* { dg-error "expected '\\\(' before end of line" } */
   for (int i = 0; i < 100; ++i)
--- gcc/testsuite/c-c++-common/gomp/tile-12.c.jj	2024-06-06 22:11:22.860432400 +0200
+++ gcc/testsuite/c-c++-common/gomp/tile-12.c	2024-07-09 10:20:38.924716231 +0200
@@ -35,9 +35,9 @@  test (void)
     dummy (i);
 
   #pragma omp parallel for
-  #pragma omp tile sizes(1,2 /* { dg-error "expected ',' before end of line" } */
-  for (int i = 0; i < 100; ++i)
-    dummy (i);
+  #pragma omp tile sizes(1,2 /* { dg-error "expected '\\\)' before end of line" "" { target c } } */
+  for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" "" { target c } } */
+    dummy (i); /* { dg-error "expected ',' before end of line" "" { target c++ } .-2 } */
 
   #pragma omp parallel for
   #pragma omp tile sizes /* { dg-error "expected '\\\(' before end of line" } */