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]

[gomp3] Region nesting diagnostics


Hi!

check_omp_nesting_restrictions wasn't testing any nesting restrictions
regarding explicit tasks (most of the omp pragmas must not be used
in task regions, with the notable exception of #pragma omp parallel)
and additionally no checking has been done for invalid use of #pragma omp
barrier.  This patch adds the diagnostics.
There are libgomp tests that actually use #pragma omp barrier inside
of #pragma omp for, but those should be ok, as the loops have the same
number of iterations as threads in the team and they need some kind of
barrier to check the firstprivate/lastprivate behavior, so I've just
added expected dg-warning for them.

Regtested on x86_64-linux, committed to gomp-3_0-branch.

2008-03-07  Jakub Jelinek  <jakub@redhat.com>

	* omp-low.c (check_omp_nesting_restrictions): Warn if work-sharing,
	barrier, master or ordered region is closely nested inside OMP_TASK.
	Add warnings for barrier if closely nested inside of work-sharing,
	ordered, or master region.
	(scan_omp_1): Call check_omp_nesting_restrictions even for
	GOMP_barrier calls.
	* gimplify.c (gimplify_expr): Handle OMP_SECTIONS_SWITCH.

	* gcc.dg/gomp/appendix-a/a.35.4.c: Add dg-warning.
	* gcc.dg/gomp/appendix-a/a.35.6.c: Likewise.
	* gfortran.dg/gomp/appendix-a/a.35.4.f90: Likewise.
	* gfortran.dg/gomp/appendix-a/a.35.6.f90: Likewise.
	* gcc.dg/gomp/nesting-1.c: New test.

	* testsuite/libgomp.fortran/vla4.f90: Add dg-warning.
	* testsuite/libgomp.fortran/vla5.f90: Likewise.
	* testsuite/libgomp.c/pr26943-2.c: Likewise.
	* testsuite/libgomp.c/pr26943-3.c: Likewise.
	* testsuite/libgomp.c/pr26943-4.c: Likewise.

--- gcc/omp-low.c.jj	2008-02-28 13:47:00.000000000 +0100
+++ gcc/omp-low.c	2008-03-05 18:13:59.000000000 +0100
@@ -1436,6 +1436,7 @@ check_omp_nesting_restrictions (tree t, 
     case OMP_FOR:
     case OMP_SECTIONS:
     case OMP_SINGLE:
+    case CALL_EXPR:
       for (; ctx != NULL; ctx = ctx->outer)
 	switch (TREE_CODE (ctx->stmt))
 	  {
@@ -1444,8 +1445,17 @@ check_omp_nesting_restrictions (tree t, 
 	  case OMP_SINGLE:
 	  case OMP_ORDERED:
 	  case OMP_MASTER:
+	  case OMP_TASK:
+	    if (TREE_CODE (t) == CALL_EXPR)
+	      {
+		warning (0, "barrier region may not be closely nested inside "
+			    "of work-sharing, critical, ordered, master or "
+			    "explicit task region");
+		return;
+	      }
 	    warning (0, "work-sharing region may not be closely nested inside "
-			"of work-sharing, critical, ordered or master region");
+			"of work-sharing, critical, ordered, master or explicit "
+			"task region");
 	    return;
 	  case OMP_PARALLEL:
 	    return;
@@ -1460,8 +1470,9 @@ check_omp_nesting_restrictions (tree t, 
 	  case OMP_FOR:
 	  case OMP_SECTIONS:
 	  case OMP_SINGLE:
+	  case OMP_TASK:
 	    warning (0, "master region may not be closely nested inside "
-			"of work-sharing region");
+			"of work-sharing or explicit task region");
 	    return;
 	  case OMP_PARALLEL:
 	    return;
@@ -1474,8 +1485,9 @@ check_omp_nesting_restrictions (tree t, 
 	switch (TREE_CODE (ctx->stmt))
 	  {
 	  case OMP_CRITICAL:
+	  case OMP_TASK:
 	    warning (0, "ordered region may not be closely nested inside "
-			"of critical region");
+			"of critical or explicit task region");
 	    return;
 	  case OMP_FOR:
 	    if (find_omp_clause (OMP_CLAUSES (ctx->stmt),
@@ -1518,8 +1530,18 @@ scan_omp_1 (tree *tp, int *walk_subtrees
     input_location = EXPR_LOCATION (t);
 
   /* Check the OpenMP nesting restrictions.  */
-  if (OMP_DIRECTIVE_P (t) && ctx != NULL)
-    check_omp_nesting_restrictions (t, ctx);
+  if (ctx != NULL)
+    {
+      if (OMP_DIRECTIVE_P (t))
+	check_omp_nesting_restrictions (t, ctx);
+      else if (TREE_CODE (t) == CALL_EXPR)
+	{
+	  tree fndecl = get_callee_fndecl (t);
+	  if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+	      && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_GOMP_BARRIER)
+	    check_omp_nesting_restrictions (t, ctx);
+	}
+    }
 
   *walk_subtrees = 0;
   switch (TREE_CODE (t))
--- gcc/gimplify.c.jj	2008-02-27 17:57:57.000000000 +0100
+++ gcc/gimplify.c	2008-03-06 12:59:40.000000000 +0100
@@ -6161,8 +6161,9 @@ gimplify_expr (tree *expr_p, tree *pre_p
 
 	case OMP_RETURN:
 	case OMP_CONTINUE:
-        case OMP_ATOMIC_LOAD:
-        case OMP_ATOMIC_STORE:
+	case OMP_ATOMIC_LOAD:
+	case OMP_ATOMIC_STORE:
+	case OMP_SECTIONS_SWITCH:
 
 	  ret = GS_ALL_DONE;
 	  break;
--- libgomp/testsuite/libgomp.fortran/vla4.f90.jj	2007-11-14 12:27:46.000000000 +0100
+++ libgomp/testsuite/libgomp.fortran/vla4.f90	2008-03-06 14:05:29.000000000 +0100
@@ -94,7 +94,7 @@ contains
     forall (p = 1:2, q = 3:7, r = 1:7) u(p, q, r) = 30 - x - p + q - 2 * r
     forall (p = 1:5, q = 3:7, p + q .le. 8) v(p, q) = w(1:7)
     forall (p = 1:5, q = 3:7, p + q .gt. 8) v(p, q) = w(20:26)
-!$omp barrier
+!$omp barrier		! { dg-warning "may not be closely nested" }
     y = ''
     if (x .eq. 0) y = '0'
     if (x .eq. 1) y = '1'
--- libgomp/testsuite/libgomp.fortran/vla5.f90.jj	2007-11-14 12:27:46.000000000 +0100
+++ libgomp/testsuite/libgomp.fortran/vla5.f90	2008-03-06 14:05:20.000000000 +0100
@@ -66,7 +66,7 @@ contains
     forall (p = 1:2, q = 3:7, r = 1:7) u(p, q, r) = 30 - x - p + q - 2 * r
     forall (p = 1:5, q = 3:7, p + q .le. 8) v(p, q) = w(1:7)
     forall (p = 1:5, q = 3:7, p + q .gt. 8) v(p, q) = w(20:26)
-!$omp barrier
+!$omp barrier		! { dg-warning "may not be closely nested" }
     y = ''
     if (x .eq. 0) y = '0'
     if (x .eq. 1) y = '1'
--- libgomp/testsuite/libgomp.c/pr26943-2.c.jj	2007-11-14 12:27:48.000000000 +0100
+++ libgomp/testsuite/libgomp.c/pr26943-2.c	2008-03-06 14:06:57.000000000 +0100
@@ -20,7 +20,7 @@ main (void)
     {
       if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
 	j++;
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
 #pragma omp atomic
       a += i;
       b += i;
@@ -31,7 +31,7 @@ main (void)
       f[0] += i;
       g[0] = 'g' + i;
       h[0] = 'h' + i;
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
       if (a != 8 + 6 || b != 12 + i || c != i || d != i)
 	j += 8;
       if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
--- libgomp/testsuite/libgomp.c/pr26943-3.c.jj	2007-11-14 12:27:48.000000000 +0100
+++ libgomp/testsuite/libgomp.c/pr26943-3.c	2008-03-06 14:07:16.000000000 +0100
@@ -26,7 +26,7 @@ main (void)
 	{
 	  if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
 	    j++;
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
 #pragma omp atomic
 	  a += i;
 	  b += i;
@@ -37,7 +37,7 @@ main (void)
 	  f[0] += i;
 	  g[0] = 'g' + i;
 	  h[0] = 'h' + i;
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
 	  if (a != 8 + 6 || b != 12 + i || c != i || d != i)
 	    j += 8;
 	  if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
--- libgomp/testsuite/libgomp.c/pr26943-4.c.jj	2007-11-14 12:27:48.000000000 +0100
+++ libgomp/testsuite/libgomp.c/pr26943-4.c	2008-03-07 11:44:05.000000000 +0100
@@ -27,7 +27,7 @@ main (void)
 	{
 	  if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
 	    j++;
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
 #pragma omp atomic
 	  a += i;
 	  b += i;
@@ -38,7 +38,7 @@ main (void)
 	  f[0] += i;
 	  g[0] = 'g' + i;
 	  h[0] = 'h' + i;
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
 	  if (a != 8 + 6 || b != 12 + i || c != i || d != i)
 	    j += 8;
 	  if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
--- gcc/testsuite/gcc.dg/gomp/appendix-a/a.35.6.c.jj	2007-11-14 12:31:26.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/appendix-a/a.35.6.c	2008-03-05 19:21:50.000000000 +0100
@@ -9,7 +9,7 @@ wrong6 (int n)
     {
       work (n, 0);
 /* incorrect nesting of barrier region in a single region */
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
       work (n, 1);
     }
   }
--- gcc/testsuite/gcc.dg/gomp/appendix-a/a.35.4.c.jj	2007-11-14 12:31:26.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/appendix-a/a.35.4.c	2008-03-05 18:48:45.000000000 +0100
@@ -11,7 +11,7 @@ wrong4 (int n)
       {
 	work (i, 0);
 	/* incorrect nesting of barrier region in a loop region */
-#pragma omp barrier
+#pragma omp barrier	/* { dg-warning "may not be closely nested" } */
 	work (i, 1);
       }
   }
--- gcc/testsuite/gcc.dg/gomp/nesting-1.c.jj	2008-03-06 12:02:00.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/nesting-1.c	2008-03-06 12:11:07.000000000 +0100
@@ -0,0 +1,198 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+void
+f1 (void)
+{
+  int i, j;
+  #pragma omp for
+  for (i = 0; i < 3; i++)
+    {
+      #pragma omp for		/* { dg-warning "may not be closely nested" } */
+      for (j = 0; j < 3; j++)
+	;
+      #pragma omp sections	/* { dg-warning "may not be closely nested" } */
+      {
+	;
+      #pragma omp section
+	;
+      }
+      #pragma omp single	/* { dg-warning "may not be closely nested" } */
+	;
+    #pragma omp master		/* { dg-warning "may not be closely nested" } */
+      ;
+      #pragma omp barrier	/* { dg-warning "may not be closely nested" } */
+    }
+  #pragma omp sections
+  {
+    #pragma omp for		/* { dg-warning "may not be closely nested" } */
+    for (j = 0; j < 3; j++)
+      ;
+    #pragma omp sections	/* { dg-warning "may not be closely nested" } */
+    {
+      ;
+    #pragma omp section
+      ;
+    }
+    #pragma omp single		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp master		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp section
+      ;
+  }
+  #pragma omp single
+  {
+    #pragma omp for		/* { dg-warning "may not be closely nested" } */
+    for (j = 0; j < 3; j++)
+      ;
+    #pragma omp sections	/* { dg-warning "may not be closely nested" } */
+    {
+      ;
+    #pragma omp section
+      ;
+    }
+    #pragma omp single		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp master		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp barrier		/* { dg-warning "may not be closely nested" } */
+  }
+  #pragma omp master
+  {
+    #pragma omp for		/* { dg-warning "may not be closely nested" } */
+    for (j = 0; j < 3; j++)
+      ;
+    #pragma omp sections	/* { dg-warning "may not be closely nested" } */
+    {
+      ;
+    #pragma omp section
+      ;
+    }
+    #pragma omp single		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp master
+      ;
+    #pragma omp barrier		/* { dg-warning "may not be closely nested" } */
+  }
+  #pragma omp task
+  {
+    #pragma omp for		/* { dg-warning "may not be closely nested" } */
+    for (j = 0; j < 3; j++)
+      ;
+    #pragma omp sections	/* { dg-warning "may not be closely nested" } */
+    {
+      ;
+    #pragma omp section
+      ;
+    }
+    #pragma omp single		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp master		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp barrier		/* { dg-warning "may not be closely nested" } */
+  }
+  #pragma omp parallel
+  {
+    #pragma omp for
+    for (j = 0; j < 3; j++)
+      ;
+    #pragma omp sections
+    {
+      ;
+    #pragma omp section
+      ;
+    }
+    #pragma omp single
+      ;
+    #pragma omp master
+      ;
+    #pragma omp barrier
+  }
+}
+
+void
+f2 (void)
+{
+  int i, j;
+  #pragma omp ordered
+  {
+    #pragma omp for		/* { dg-warning "may not be closely nested" } */
+    for (j = 0; j < 3; j++)
+      ;
+    #pragma omp sections	/* { dg-warning "may not be closely nested" } */
+    {
+      ;
+    #pragma omp section
+      ;
+    }
+    #pragma omp single		/* { dg-warning "may not be closely nested" } */
+      ;
+    #pragma omp master
+      ;
+    #pragma omp barrier		/* { dg-warning "may not be closely nested" } */
+  }
+}
+
+void
+f3 (void)
+{
+  #pragma omp critical
+  {
+    #pragma omp ordered		/* { dg-warning "may not be closely nested" } */
+      ;
+  }
+}
+
+void
+f4 (void)
+{
+  #pragma omp task
+  {
+    #pragma omp ordered		/* { dg-warning "may not be closely nested" } */
+      ;
+  }
+}
+
+void
+f5 (void)
+{
+  int i;
+  #pragma omp for
+  for (i = 0; i < 10; i++)
+    {
+      #pragma omp ordered		/* { dg-warning "must be closely nested" } */
+	;
+    }
+  #pragma omp for ordered
+  for (i = 0; i < 10; i++)
+    {
+      #pragma omp ordered
+	;
+    }
+}
+
+void
+f6 (void)
+{
+  #pragma omp critical (foo)
+    #pragma omp critical (bar)
+      ;
+  #pragma omp critical
+    #pragma omp critical (baz)
+      ;
+}
+
+void
+f7 (void)
+{
+  #pragma omp critical (foo2)
+    #pragma omp critical
+      ;
+  #pragma omp critical (bar)
+    #pragma omp critical (bar)		/* { dg-warning "may not be nested" } */
+      ;
+  #pragma omp critical
+    #pragma omp critical		/* { dg-warning "may not be nested" } */
+      ;
+}
--- gcc/testsuite/gfortran.dg/gomp/appendix-a/a.35.6.f90.jj	2007-11-14 12:36:29.000000000 +0100
+++ gcc/testsuite/gfortran.dg/gomp/appendix-a/a.35.6.f90	2008-03-05 19:21:22.000000000 +0100
@@ -6,7 +6,7 @@
 !$OMP SINGLE
            CALL WORK(N,1)
 ! incorrect nesting of barrier region in a single region
-!$OMP BARRIER
+!$OMP BARRIER	! { dg-warning "may not be closely nested" }
             CALL WORK(N,2)
 !$OMP END SINGLE
 !$OMP END PARALLEL
--- gcc/testsuite/gfortran.dg/gomp/appendix-a/a.35.4.f90.jj	2007-11-14 12:36:29.000000000 +0100
+++ gcc/testsuite/gfortran.dg/gomp/appendix-a/a.35.4.f90	2008-03-05 18:49:27.000000000 +0100
@@ -8,7 +8,7 @@
           DO I = 1, N
              CALL WORK(I, 1)
 ! incorrect nesting of barrier region in a loop region
-!$OMP BARRIER
+!$OMP BARRIER	! { dg-warning "may not be closely nested" }
              CALL WORK(I, 2)
           END DO
 !$OMP END PARALLEL

	Jakub


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