Hi!

Multiple depend(source) is useless and it has been agreed on that we should
disallow it.  Similarly, when mixing sink and source on the same ordered
construct, we'd either need to define behavior for it, or disallow it, where
the latter is what we've done for clarity reasons.

The testcase also verifies diagnostics for the case where ordered is less
than collapse.

2015-10-13  Jakub Jelinek  <ja...@redhat.com>

        * gimplify.c (gimplify_omp_ordered): Disallow multiple
        depend(source) clauses on the same construct.  Disallow depend(source)
        combined with depend(sink:vec) on the same construct.
        * omp-low.c (check_omp_nesting_restrictions): Remove pointless
        asserts.
testsuite/
        * c-c++-common/gomp/doacross-1.c: New test.

--- gcc/gimplify.c.jj   2015-10-09 09:28:04.000000000 +0200
+++ gcc/gimplify.c      2015-10-12 12:37:32.065883694 +0200
@@ -8743,6 +8743,8 @@ gimplify_omp_ordered (tree expr, gimple_
   tree c, decls;
   int failures = 0;
   unsigned int i;
+  tree source_c = NULL_TREE;
+  tree sink_c = NULL_TREE;
 
   if (gimplify_omp_ctxp)
     for (c = OMP_ORDERED_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
@@ -8772,13 +8774,33 @@ gimplify_omp_ordered (tree expr, gimple_
          if (!fail && i != gimplify_omp_ctxp->loop_iter_var.length () / 2)
            {
              error_at (OMP_CLAUSE_LOCATION (c),
-                       "number of variables in depend(sink) "
+                       "number of variables in %<depend(sink)%> "
                        "clause does not match number of "
                        "iteration variables");
-             fail = true;
              failures++;
            }
+         sink_c = c;
        }
+      else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
+              && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SOURCE)
+       {
+         if (source_c)
+           {
+             error_at (OMP_CLAUSE_LOCATION (c),
+                       "more than one %<depend(source)%> clause on an "
+                       "%<ordered%> construct");
+             failures++;
+           }
+         else
+           source_c = c;
+       }
+  if (source_c && sink_c)
+    {
+      error_at (OMP_CLAUSE_LOCATION (source_c),
+               "%<depend(source)%> clause specified together with "
+               "%<depend(sink:)%> clauses on the same construct");
+      failures++;
+    }
 
   if (failures)
     return gimple_build_nop ();
--- gcc/omp-low.c.jj    2015-10-02 11:38:40.000000000 +0200
+++ gcc/omp-low.c       2015-10-12 12:21:32.081523021 +0200
@@ -3348,8 +3348,6 @@ check_omp_nesting_restrictions (gimple s
                || OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK))
          {
            enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_KIND (c);
-           gcc_assert (kind == OMP_CLAUSE_DEPEND_SOURCE
-                       || kind == OMP_CLAUSE_DEPEND_SINK);
            error_at (OMP_CLAUSE_LOCATION (c),
                      "%<depend(%s)%> is only allowed in %<omp ordered%>",
                      kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink");
@@ -3455,8 +3453,6 @@ check_omp_nesting_restrictions (gimple s
                || OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK))
          {
            enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_KIND (c);
-           gcc_assert (kind == OMP_CLAUSE_DEPEND_SOURCE
-                       || kind == OMP_CLAUSE_DEPEND_SINK);
            error_at (OMP_CLAUSE_LOCATION (c),
                      "%<depend(%s)%> is only allowed in %<omp ordered%>",
                      kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink");
--- gcc/testsuite/c-c++-common/gomp/doacross-1.c.jj     2015-10-12 
12:01:39.528659576 +0200
+++ gcc/testsuite/c-c++-common/gomp/doacross-1.c        2015-10-12 
12:46:57.691262361 +0200
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+void
+foo (void)
+{
+  int i, j, k;
+  #pragma omp for ordered (1)
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered depend (sink: i - 1)
+      #pragma omp ordered depend (source)
+    }
+  #pragma omp for ordered (1) collapse (1)
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered depend (sink: i - 1)
+      #pragma omp ordered depend (source)
+    }
+  #pragma omp for collapse (2) ordered (1)             /* { dg-error "clause 
parameter is less than" } */
+  for (i = 0; i < 64; i++)
+    for (j = 0; j < 64; j++)
+      {
+       #pragma omp ordered depend (sink: i - 1)        /* { dg-error "does not 
match number" } */
+       #pragma omp ordered depend (source)
+      }
+  #pragma omp for ordered (2) collapse (3)             /* { dg-error "clause 
parameter is less than" } */
+  for (i = 0; i < 64; i++)
+    for (j = 0; j < 64; j++)
+      for (k = 0; k < 64; k++)
+       {
+         #pragma omp ordered depend (sink: i - 1, j - 2) /* { dg-error "does 
not match number" } */
+         #pragma omp ordered depend (source)
+       }
+  #pragma omp ordered depend (sink: j)                 /* { dg-error "clause 
must be closely nested inside an ordered loop" } */
+  #pragma omp ordered depend (source)                  /* { dg-error "clause 
must be closely nested inside an ordered loop" } */
+  #pragma omp for ordered (1)
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered depend (sink: i - 1) depend (sink: i - 2)
+      #pragma omp ordered depend (source) depend (source) /* { dg-error "more 
than one .depend.source.. clause on an" } */
+    }
+  #pragma omp for ordered (1)
+  for (i = 0; i < 64; i++)
+    {
+      #pragma omp ordered depend (sink: i - 1) depend (source) depend (sink: i 
- 2) /* { dg-error "clause specified together with" } */
+    }
+}

        Jakub

Reply via email to