Hi!

We ICE on the following invalid testcase, because we failed to diagnose if
ordered construct without depend clause binds to loop with ordered(n) clause
(i.e. doacross loop).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk so far.

Not happy about the sink-3.c extra diagnostics, when I find time, I'll
change the depend sink clause parsing so that the clauses aren't removed,
but kept say with error_mark_node OMP_CLAUSE_DECL and can be removed only during
gimplification together with the whole construct.

2018-10-19  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/85488
        PR middle-end/87649
        * omp-low.c (check_omp_nesting_restrictions): Diagnose ordered without
        depend closely nested inside of loop with ordered clause with
        a parameter.

        * c-c++-common/gomp/doacross-2.c: New test.
        * c-c++-common/gomp/sink-3.c: Expect another error during error
        recovery.

--- gcc/omp-low.c.jj    2018-08-27 17:50:42.804505831 +0200
+++ gcc/omp-low.c       2018-10-19 11:43:46.924579912 +0200
@@ -2762,14 +2762,25 @@ check_omp_nesting_restrictions (gimple *
          case GIMPLE_OMP_FOR:
            if (gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_TASKLOOP)
              goto ordered_in_taskloop;
-           if (omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
-                                OMP_CLAUSE_ORDERED) == NULL)
+           tree o;
+           o = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
+                                OMP_CLAUSE_ORDERED);
+           if (o == NULL)
              {
                error_at (gimple_location (stmt),
                          "%<ordered%> region must be closely nested inside "
                          "a loop region with an %<ordered%> clause");
                return false;
              }
+           if (OMP_CLAUSE_ORDERED_EXPR (o) != NULL_TREE
+               && omp_find_clause (c, OMP_CLAUSE_DEPEND) == NULL_TREE)
+             {
+               error_at (gimple_location (stmt),
+                         "%<ordered%> region without %<depend%> clause may "
+                         "not be closely nested inside a loop region with "
+                         "an %<ordered%> clause with a parameter");
+               return false;
+             }
            return true;
          case GIMPLE_OMP_TARGET:
            if (gimple_omp_target_kind (ctx->stmt)
--- gcc/testsuite/c-c++-common/gomp/doacross-2.c.jj     2018-10-19 
11:38:19.185057188 +0200
+++ gcc/testsuite/c-c++-common/gomp/doacross-2.c        2018-10-19 
11:38:11.027193588 +0200
@@ -0,0 +1,49 @@
+/* PR middle-end/87649 */
+
+void
+foo (void)
+{
+  int i;
+  #pragma omp for ordered(1)
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered                      /* { dg-error "'ordered' region 
without 'depend' clause may not be closely nested inside a loop region with an 
'ordered' clause with a parameter" } */
+      ;
+    }
+  #pragma omp for ordered(1)
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered threads              /* { dg-error "'ordered' region 
without 'depend' clause may not be closely nested inside a loop region with an 
'ordered' clause with a parameter" } */
+      ;
+    }
+}
+
+void
+bar (void)
+{
+  int i;
+  #pragma omp for ordered
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered depend(source)       /* { dg-error "'ordered' 
construct with 'depend' clause must be closely nested inside a loop with 
'ordered' clause with a parameter" } */
+      #pragma omp ordered depend(sink: i - 1)  /* { dg-error "'ordered' 
construct with 'depend' clause must be closely nested inside a loop with 
'ordered' clause with a parameter" } */
+    }
+  #pragma omp for
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered depend(source)       /* { dg-error "'ordered' 
construct with 'depend' clause must be closely nested inside a loop with 
'ordered' clause with a parameter" } */
+      #pragma omp ordered depend(sink: i - 1)  /* { dg-error "'ordered' 
construct with 'depend' clause must be closely nested inside a loop with 
'ordered' clause with a parameter" } */
+    }
+  #pragma omp for
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered                      /* { dg-error "'ordered' region 
must be closely nested inside a loop region with an 'ordered' clause" } */
+      ;
+    }
+  #pragma omp for
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered threads              /* { dg-error "'ordered' region 
must be closely nested inside a loop region with an 'ordered' clause" } */
+      ;
+    }
+}
--- gcc/testsuite/c-c++-common/gomp/sink-3.c.jj 2015-10-13 20:57:40.712493500 
+0200
+++ gcc/testsuite/c-c++-common/gomp/sink-3.c    2018-10-19 12:03:27.326879161 
+0200
@@ -14,7 +14,7 @@ foo ()
   for (i=0; i < 100; ++i)
     {
 #pragma omp ordered depend(sink:poo-1,paa+1) /* { dg-error 
"poo.*declared.*paa.*declared" } */
-    bar(&i);
+    bar(&i);                                /* { dg-error "may not be closely 
nested" "" { target *-*-* } .-1 } */
 #pragma omp ordered depend(source)
     }
 }

        Jakub

Reply via email to