This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp] Accept optional comma in between omp clauses (PR c/34506)


Hi!

OpenMP 2.5 (and 3.0 too) allows a single comma in between omp clauses.
The Fortran FE was already handling this, but the C and C++ parsers did not.

Fixed thusly, regtested on x86_64-linux.  Ok for trunk?

2007-12-17  Jakub Jelinek  <jakub@redhat.com>

	PR c/34506
	* c-parser.c (c_parser_omp_all_clauses): Accept optional comma
	in between clauses.

	* parser.c (cp_parser_omp_all_clauses): Accept optional comma
	in between clauses.

	* gcc.dg/gomp/clause-2.c: New test.
	* g++.dg/gomp/clause-4.C: New test.

--- gcc/c-parser.c.jj	2007-12-05 21:42:09.000000000 +0100
+++ gcc/c-parser.c	2007-12-17 10:04:14.000000000 +0100
@@ -7262,14 +7262,22 @@ c_parser_omp_all_clauses (c_parser *pars
 			  const char *where)
 {
   tree clauses = NULL;
+  bool first = true;
 
   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
     {
-      location_t here = c_parser_peek_token (parser)->location;
-      const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
+      location_t here;
+      pragma_omp_clause c_kind;
       const char *c_name;
       tree prev = clauses;
 
+      if (!first && c_parser_next_token_is (parser, CPP_COMMA))
+	c_parser_consume_token (parser);
+
+      first = false;
+      here = c_parser_peek_token (parser)->location;
+      c_kind = c_parser_omp_clause_name (parser);
+
       switch (c_kind)
 	{
 	case PRAGMA_OMP_CLAUSE_COPYIN:
--- gcc/cp/parser.c.jj	2007-12-05 21:42:07.000000000 +0100
+++ gcc/cp/parser.c	2007-12-17 13:23:29.000000000 +0100
@@ -19671,13 +19671,20 @@ cp_parser_omp_all_clauses (cp_parser *pa
 			   const char *where, cp_token *pragma_tok)
 {
   tree clauses = NULL;
+  bool first = true;
 
   while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
     {
-      pragma_omp_clause c_kind = cp_parser_omp_clause_name (parser);
+      pragma_omp_clause c_kind;
       const char *c_name;
       tree prev = clauses;
 
+      if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+	cp_lexer_consume_token (parser->lexer);
+
+      c_kind = cp_parser_omp_clause_name (parser);
+      first = false;
+
       switch (c_kind)
 	{
 	case PRAGMA_OMP_CLAUSE_COPYIN:
--- gcc/testsuite/gcc.dg/gomp/clause-2.c.jj	2007-12-17 10:06:38.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/clause-2.c	2007-12-17 10:35:32.000000000 +0100
@@ -0,0 +1,23 @@
+/* PR c/34506 */
+/* { dg-do compile } */
+
+#define p parallel
+
+void
+foo (int x)
+{
+#pragma omp p num_threads (4) if (1) private (x)
+    ;
+#pragma omp p num_threads(4)if(1)private(x)
+    ;
+#pragma omp p num_threads (4), if (1) , private (x)
+    ;
+#pragma omp p num_threads(4),if(1),private(x)
+    ;
+#pragma omp p, num_threads (4), if (1), private (x)	/* { dg-error "clause before" } */
+    ;
+#pragma omp p num_threads (4), if (1), private (x),	/* { dg-error "clause before" } */
+    ;
+#pragma omp p num_threads (4), , if (1), private (x)	/* { dg-error "clause before" } */
+    ;
+}
--- gcc/testsuite/g++.dg/gomp/clause-4.C.jj	2007-12-17 10:06:38.000000000 +0100
+++ gcc/testsuite/g++.dg/gomp/clause-4.C	2007-12-17 10:36:40.000000000 +0100
@@ -0,0 +1,23 @@
+// PR c/34506
+// { dg-do compile }
+
+#define p parallel
+
+void
+foo (int x)
+{
+#pragma omp p num_threads (4) if (1) private (x)
+    ;
+#pragma omp p num_threads(4)if(1)private(x)
+    ;
+#pragma omp p num_threads (4), if (1) , private (x)
+    ;
+#pragma omp p num_threads(4),if(1),private(x)
+    ;
+#pragma omp p, num_threads (4), if (1), private (x)	// { dg-error "clause before" }
+    ;
+#pragma omp p num_threads (4), if (1), private (x),	// { dg-error "clause before" }
+    ;
+#pragma omp p num_threads (4), , if (1), private (x)	// { dg-error "clause before" }
+    ;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]