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]

[committed] Improve test coverage of duplicated clauses, fix whatever it found (PR c/91401)


Hi!

Through code inspection I found that in C duplicate proc_bind wasn't
diagnosed (but in C++ it was).  So, I've added following test coverage
for various other cases where duplication shall be diagnosed, and fixed
whatever that revealed (besides proc_bind also the target {enter,exit} data
if clause modifier has been incorrectly printed as just {enter,exit} data).

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2019-08-09  Jakub Jelinek  <jakub@redhat.com>

c/
	* c-parser.c (check_no_duplicate_clause): Simplify using
	omp_find_clause.
	(c_parser_omp_clause_if): Fix up printing of target {enter,exit} data
	directive name modifiers.
	(c_parser_omp_clause_proc_bind): Check for duplicate proc_bind clause.
cp/
	* parser.c (check_no_duplicate_clause): Simplify using
	omp_find_clause.
	(cp_parser_omp_clause_if): Fix up printing of target {enter,exit} data
	directive name modifiers.
testsuite/
	* c-c++-common/gomp/if-4.c: New test.
	* c-c++-common/gomp/clause-dups-1.c: New test.

--- gcc/c/c-parser.c.jj	2019-08-08 13:09:14.645488373 +0200
+++ gcc/c/c-parser.c	2019-08-08 17:52:01.123649009 +0200
@@ -11898,15 +11898,8 @@ static void
 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
 			   const char *name)
 {
-  tree c;
-
-  for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
-    if (OMP_CLAUSE_CODE (c) == code)
-      {
-	location_t loc = OMP_CLAUSE_LOCATION (c);
-	error_at (loc, "too many %qs clauses", name);
-	break;
-      }
+  if (tree c = omp_find_clause (clauses, code))
+    error_at (OMP_CLAUSE_LOCATION (c), "too many %qs clauses", name);
 }
 
 /* OpenACC 2.0
@@ -12616,8 +12609,8 @@ c_parser_omp_clause_if (c_parser *parser
 	      case OMP_TARGET_DATA: p = "target data"; break;
 	      case OMP_TARGET: p = "target"; break;
 	      case OMP_TARGET_UPDATE: p = "target update"; break;
-	      case OMP_TARGET_ENTER_DATA: p = "enter data"; break;
-	      case OMP_TARGET_EXIT_DATA: p = "exit data"; break;
+	      case OMP_TARGET_ENTER_DATA: p = "target enter data"; break;
+	      case OMP_TARGET_EXIT_DATA: p = "target exit data"; break;
 	      default: gcc_unreachable ();
 	      }
 	    error_at (location, "too many %<if%> clauses with %qs modifier",
@@ -14853,6 +14849,7 @@ c_parser_omp_clause_proc_bind (c_parser
   else
     goto invalid_kind;
 
+  check_no_duplicate_clause (list, OMP_CLAUSE_PROC_BIND, "proc_bind");
   c_parser_consume_token (parser);
   parens.skip_until_found_close (parser);
   c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
--- gcc/cp/parser.c.jj	2019-08-08 13:09:14.649488313 +0200
+++ gcc/cp/parser.c	2019-08-08 17:33:26.701273982 +0200
@@ -32684,14 +32684,8 @@ static void
 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
 			   const char *name, location_t location)
 {
-  tree c;
-
-  for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
-    if (OMP_CLAUSE_CODE (c) == code)
-      {
-	error_at (location, "too many %qs clauses", name);
-	break;
-      }
+  if (omp_find_clause (clauses, code))
+    error_at (location, "too many %qs clauses", name);
 }
 
 /* OpenMP 2.5:
@@ -33581,8 +33575,8 @@ cp_parser_omp_clause_if (cp_parser *pars
 	      case OMP_TARGET_DATA: p = "target data"; break;
 	      case OMP_TARGET: p = "target"; break;
 	      case OMP_TARGET_UPDATE: p = "target update"; break;
-	      case OMP_TARGET_ENTER_DATA: p = "enter data"; break;
-	      case OMP_TARGET_EXIT_DATA: p = "exit data"; break;
+	      case OMP_TARGET_ENTER_DATA: p = "target enter data"; break;
+	      case OMP_TARGET_EXIT_DATA: p = "target exit data"; break;
 	      default: gcc_unreachable ();
 	      }
 	    error_at (location, "too many %<if%> clauses with %qs modifier",
--- gcc/testsuite/c-c++-common/gomp/if-4.c.jj	2019-08-08 14:23:14.061505978 +0200
+++ gcc/testsuite/c-c++-common/gomp/if-4.c	2019-08-08 14:55:45.754305132 +0200
@@ -0,0 +1,60 @@
+void f0 (void);
+
+void
+f1 (int *p)
+{
+  int i;
+  #pragma omp task if (0) if (0)		/* { dg-error "too many 'if' clauses without modifier" } */
+  f0 ();
+  #pragma omp task if (0) if (1)		/* { dg-error "too many 'if' clauses without modifier" } */
+  f0 ();
+  #pragma omp task if (task:0) if (task:0)	/* { dg-error "too many 'if' clauses with 'task' modifier" } */
+  f0 ();
+  #pragma omp task if (task:0) if (1)		/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  f0 ();
+  #pragma omp task if (0) if (task:1)		/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  f0 ();
+  #pragma omp taskloop if (0) if (0)		/* { dg-error "too many 'if' clauses without modifier" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop if (0) if (1)		/* { dg-error "too many 'if' clauses without modifier" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop if (taskloop:0) if (taskloop:0)	/* { dg-error "too many 'if' clauses with 'taskloop' modifier" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop if (taskloop:0) if (1)		/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop if (0) if (taskloop:0)		/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp target data if (1) if (1) map (alloc: i)		/* { dg-error "too many 'if' clauses without modifier" } */
+  f0 ();
+  #pragma omp target data if (target data: 1) if (target data:0) map (alloc: i)	/* { dg-error "too many 'if' clauses with 'target data' modifier" } */
+  f0 ();
+  #pragma omp target data if (1) if (target data:0) map (alloc: i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  f0 ();
+  #pragma omp target data if (target data: 1) if (0) map (alloc: i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  f0 ();
+  #pragma omp target enter data if (1) if (1) map (to: i)		/* { dg-error "too many 'if' clauses without modifier" } */
+  #pragma omp target enter data if (target enter data: 1) if (target enter data:0) map (to: i)	/* { dg-error "too many 'if' clauses with 'target enter data' modifier" } */
+  #pragma omp target enter data if (1) if (target enter data:0) map (to: i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  #pragma omp target enter data if (target enter data: 1) if (0) map (to: i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  #pragma omp target exit data if (1) if (1) map (from: i)		/* { dg-error "too many 'if' clauses without modifier" } */
+  #pragma omp target exit data if (target exit data: 1) if (target exit data:0) map (from: i)	/* { dg-error "too many 'if' clauses with 'target exit data' modifier" } */
+  #pragma omp target exit data if (1) if (target exit data:0) map (from: i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  #pragma omp target exit data if (target exit data: 1) if (0) map (from: i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  #pragma omp target if (1) if (1)		/* { dg-error "too many 'if' clauses without modifier" } */
+  f0 ();
+  #pragma omp target if (target: 1) if (target:0)	/* { dg-error "too many 'if' clauses with 'target' modifier" } */
+  f0 ();
+  #pragma omp target if (1) if (target:0)		/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  f0 ();
+  #pragma omp target if (target: 1) if (0)		/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  f0 ();
+  #pragma omp target update if (1) if (1) to (i)		/* { dg-error "too many 'if' clauses without modifier" } */
+  #pragma omp target update if (target update: 1) if (target update:0) to (i)	/* { dg-error "too many 'if' clauses with 'target update' modifier" } */
+  #pragma omp target update if (1) if (target update:0) to (i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+  #pragma omp target update if (target update: 1) if (0) to (i)	/* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */
+}
--- gcc/testsuite/c-c++-common/gomp/clause-dups-1.c.jj	2019-08-08 18:03:03.955759072 +0200
+++ gcc/testsuite/c-c++-common/gomp/clause-dups-1.c	2019-08-08 18:20:06.138502076 +0200
@@ -0,0 +1,222 @@
+void f0 (void);
+
+void
+f1 (int *p)
+{
+  int i;
+  #pragma omp parallel proc_bind (master) proc_bind (master)	/* { dg-error "too many 'proc_bind' clauses" } */
+  f0 ();
+  #pragma omp parallel proc_bind (close) proc_bind (spread)	/* { dg-error "too many 'proc_bind' clauses" } */
+  f0 ();
+  #pragma omp for schedule(static) schedule(static)		/* { dg-error "too many 'schedule' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp for schedule(dynamic,5) schedule(runtime)		/* { dg-error "too many 'schedule' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp for collapse(1) collapse(1)			/* { dg-error "too many 'collapse' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp for collapse(1) collapse(2)			/* { dg-error "too many 'collapse' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp for ordered ordered				/* { dg-error "too many 'ordered' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp for ordered(1) ordered(1)				/* { dg-error "too many 'ordered' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp for nowait nowait					/* { dg-error "too many 'nowait' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp simd collapse(1) collapse(1)			/* { dg-error "too many 'collapse' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp simd collapse(1) collapse(2)			/* { dg-error "too many 'collapse' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp simd simdlen(1) simdlen(1)			/* { dg-error "too many 'simdlen' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp simd simdlen(1) simdlen(2)			/* { dg-error "too many 'simdlen' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp simd safelen(1) safelen(1)			/* { dg-error "too many 'safelen' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp simd safelen(1) safelen(2)			/* { dg-error "too many 'safelen' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp teams
+  {
+    #pragma omp distribute collapse(1) collapse(1)			/* { dg-error "too many 'collapse' clauses" } */
+    for (i = 0; i < 8; ++i)
+      f0 ();
+    #pragma omp distribute collapse(1) collapse(2)			/* { dg-error "too many 'collapse' clauses" } */
+    for (i = 0; i < 8; ++i)
+      f0 ();
+  }
+  #pragma omp teams thread_limit (3) thread_limit (3)		/* { dg-error "too many 'thread_limit' clauses" } */
+  f0 ();
+  #pragma omp teams thread_limit (3) thread_limit (5)		/* { dg-error "too many 'thread_limit' clauses" } */
+  f0 ();
+  #pragma omp teams num_teams (3) num_teams (3)			/* { dg-error "too many 'num_teams' clauses" } */
+  f0 ();
+  #pragma omp teams num_teams (3) num_teams (5)			/* { dg-error "too many 'num_teams' clauses" } */
+  f0 ();
+  #pragma omp single nowait nowait				/* { dg-error "too many 'nowait' clauses" } */
+  f0 ();
+  #pragma omp loop bind (thread) collapse(1) collapse(3)	/* { dg-error "too many 'collapse' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp task final (0) final (0)				/* { dg-error "too many 'final' clauses" } */
+  f0 ();
+  #pragma omp task final (0) final (1)				/* { dg-error "too many 'final' clauses" } */
+  f0 ();
+  #pragma omp task priority (1) priority (1)			/* { dg-error "too many 'priority' clauses" } */
+  f0 ();
+  #pragma omp task priority (0) priority (1)			/* { dg-error "too many 'priority' clauses" } */
+  f0 ();
+  #pragma omp taskloop final (0) final (0)			/* { dg-error "too many 'final' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop final (0) final (1)			/* { dg-error "too many 'final' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop priority (1) priority (1)		/* { dg-error "too many 'priority' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop priority (0) priority (1)		/* { dg-error "too many 'priority' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop grainsize (1) grainsize (2)		/* { dg-error "too many 'grainsize' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop grainsize (2) grainsize (2)		/* { dg-error "too many 'grainsize' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop num_tasks (1) num_tasks (2)		/* { dg-error "too many 'num_tasks' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop num_tasks (2) num_tasks (2)		/* { dg-error "too many 'num_tasks' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop num_tasks (1) grainsize (2)
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop grainsize (2) num_tasks (2)
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop collapse (1) collapse (1)		/* { dg-error "too many 'collapse' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp taskloop collapse (1) collapse (2)		/* { dg-error "too many 'collapse' clauses" } */
+  for (i = 0; i < 8; ++i)
+    f0 ();
+  #pragma omp target data device (1) device (1) map (alloc: i)		/* { dg-error "too many 'device' clauses" } */
+  f0 ();
+  #pragma omp target enter data device (1) device (1) map (to: i)	/* { dg-error "too many 'device' clauses" } */
+  #pragma omp target enter data nowait nowait map (to: i)		/* { dg-error "too many 'nowait' clauses" } */
+  #pragma omp target exit data device (1) device (1) map (from: i)	/* { dg-error "too many 'device' clauses" } */
+  #pragma omp target exit data nowait nowait map (from: i)		/* { dg-error "too many 'nowait' clauses" } */
+  #pragma omp target device (1) device (1)			/* { dg-error "too many 'device' clauses" } */
+  f0 ();
+  #pragma omp target nowait nowait				/* { dg-error "too many 'nowait' clauses" } */
+  f0 ();
+  #pragma omp target update device (1) device (1) to (i)	/* { dg-error "too many 'device' clauses" } */
+  #pragma omp target update nowait nowait to (i)		/* { dg-error "too many 'nowait' clauses" } */
+  #pragma omp atomic seq_cst seq_cst				/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic release release				/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic relaxed relaxed				/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic seq_cst release				/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic release relaxed				/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic relaxed seq_cst				/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic hint(0) hint(0)				/* { dg-error "too many 'hint' clauses" } */
+  p[0]++;
+  #pragma omp atomic update seq_cst seq_cst			/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic update release release			/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic update relaxed relaxed			/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic update seq_cst release			/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic update release relaxed			/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic update relaxed seq_cst			/* { dg-error "too many memory order clauses" } */
+  p[0]++;
+  #pragma omp atomic update hint (0) hint(0)			/* { dg-error "too many 'hint' clauses" } */
+  p[0]++;
+  #pragma omp atomic write seq_cst seq_cst			/* { dg-error "too many memory order clauses" } */
+  p[0] = 0;
+  #pragma omp atomic write release release			/* { dg-error "too many memory order clauses" } */
+  p[0] = 0;
+  #pragma omp atomic write relaxed relaxed			/* { dg-error "too many memory order clauses" } */
+  p[0] = 0;
+  #pragma omp atomic write seq_cst release			/* { dg-error "too many memory order clauses" } */
+  p[0] = 0;
+  #pragma omp atomic write release relaxed			/* { dg-error "too many memory order clauses" } */
+  p[0] = 0;
+  #pragma omp atomic write relaxed seq_cst			/* { dg-error "too many memory order clauses" } */
+  p[0] = 0;
+  #pragma omp atomic write hint(0)hint(0)			/* { dg-error "too many 'hint' clauses" } */
+  p[0] = 0;
+  #pragma omp atomic read seq_cst seq_cst			/* { dg-error "too many memory order clauses" } */
+  i = p[0];
+  #pragma omp atomic read acquire acquire			/* { dg-error "too many memory order clauses" } */
+  i = p[0];
+  #pragma omp atomic read relaxed relaxed			/* { dg-error "too many memory order clauses" } */
+  i = p[0];
+  #pragma omp atomic read seq_cst acquire			/* { dg-error "too many memory order clauses" } */
+  i = p[0];
+  #pragma omp atomic read acquire relaxed			/* { dg-error "too many memory order clauses" } */
+  i = p[0];
+  #pragma omp atomic read relaxed seq_cst			/* { dg-error "too many memory order clauses" } */
+  i = p[0];
+  #pragma omp atomic read hint (0) hint(0)			/* { dg-error "too many 'hint' clauses" } */
+  i = p[0];
+  #pragma omp atomic capture seq_cst seq_cst			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture acq_rel acq_rel			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture acquire acquire			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture release release			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture relaxed relaxed			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture seq_cst acq_rel			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture acq_rel acquire			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture acquire release			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture release relaxed			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture relaxed seq_cst			/* { dg-error "too many memory order clauses" } */
+  i = p[0]++;
+  #pragma omp atomic capture hint(0) hint (0)			/* { dg-error "too many 'hint' clauses" } */
+  i = p[0]++;
+  
+}
+
+#pragma omp declare simd simdlen (4) simdlen (4)		/* { dg-error "too many 'simdlen' clauses" } */
+void f2 (int a, int b);
+#pragma omp declare simd simdlen (4) simdlen (8)		/* { dg-error "too many 'simdlen' clauses" } */
+void f3 (int a, int b);
+#pragma omp declare simd uniform (a) uniform (a)		/* { dg-error "'a' appears more than once in data clauses" } */
+void f4 (int a, int b);
+#pragma omp declare simd linear (a) linear (a)			/* { dg-error "'a' appears more than once in data clauses" } */
+void f5 (int a, int b);
+#pragma omp declare simd linear (a) linear (a:3)		/* { dg-error "'a' appears more than once in data clauses" } */
+void f6 (int a, int b);
+#pragma omp declare simd uniform (a) linear (a)			/* { dg-error "'a' appears more than once in data clauses" } */
+void f7 (int a, int b);
+#pragma omp declare simd linear (a) uniform (a)			/* { dg-error "'a' appears more than once in data clauses" } */
+void f8 (int a, int b);

	Jakub


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