Hi!

The store to the lastprivate(conditional:) private variable could be nested
inside some other construct, the following patch deals with that.

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

2019-05-27  Jakub Jelinek  <ja...@redhat.com>

        * omp-low.c (lower_omp_1) <case GIMPLE_ASSIGN>: Look through ordered,
        critical, taskgroup and section regions when looking for a region
        with non-NULL lastprivate_conditional_map.

        * testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c: New test.

--- gcc/omp-low.c.jj    2019-05-24 23:30:35.927880518 +0200
+++ gcc/omp-low.c       2019-05-27 15:33:10.855156534 +0200
@@ -10627,14 +10627,21 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p
       goto regimplify;
 
     case GIMPLE_ASSIGN:
-      if (ctx && ctx->lastprivate_conditional_map)
+      for (omp_context *up = ctx; up; up = up->outer)
        {
+         if (gimple_code (up->stmt) == GIMPLE_OMP_ORDERED
+             || gimple_code (up->stmt) == GIMPLE_OMP_CRITICAL
+             || gimple_code (up->stmt) == GIMPLE_OMP_TASKGROUP
+             || gimple_code (up->stmt) == GIMPLE_OMP_SECTION)
+           continue;
+         else if (!up->lastprivate_conditional_map)
+           break;
          tree lhs = get_base_address (gimple_assign_lhs (stmt));
          if (DECL_P (lhs))
-           if (tree *v = ctx->lastprivate_conditional_map->get (lhs))
+           if (tree *v = up->lastprivate_conditional_map->get (lhs))
              {
                tree clauses
-                 = gimple_omp_for_clauses (as_a <gomp_for *> (ctx->stmt));
+                 = gimple_omp_for_clauses (as_a <gomp_for *> (up->stmt));
                tree c = omp_find_clause (clauses, OMP_CLAUSE__CONDTEMP_);
                c = omp_find_clause (OMP_CLAUSE_CHAIN (c),
                                     OMP_CLAUSE__CONDTEMP_);
--- libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c.jj       
2019-05-27 15:35:43.549678080 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c  
2019-05-27 15:47:44.180988373 +0200
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_runtime } */
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int r, s, u, v, t;
+int *x;
+
+void
+foo (int *a)
+{
+  int i;
+  long long j;
+  #pragma omp for lastprivate (conditional: u, x) ordered
+  for (i = 15; i < 64; i++)
+    {
+      #pragma omp critical
+      {
+       if ((a[i] % 5) == 3)
+         u = i;
+      }
+      #pragma omp ordered
+      {
+       if ((a[i] % 7) == 2)
+         x = &a[i];
+      }
+    }
+  #pragma omp for lastprivate (conditional: v) reduction (+:r, s) schedule 
(nonmonotonic: static) reduction (task, +: t)
+  for (i = -3; i < 119; i += 2)
+    {
+      ++s;
+      #pragma omp taskgroup
+      {
+       #pragma omp task in_reduction (+: t)
+         ++t;
+       if ((a[i + 4] % 11) == 9)
+         v = i;
+       else
+         ++r;
+      }
+    }
+}
+
+int
+main ()
+{
+  int a[128], i;
+  for (i = 0; i < 128; i++)
+    a[i] = i;
+  #pragma omp parallel
+  foo (a);
+  if (u != 63 || v != 115 || x != &a[58] || r != 55 || s != 61 || t != 61)
+    abort ();
+  return 0;
+}

        Jakub

Reply via email to