Hi Jakub,
This patch fixes an OpenACC reduction lowering segfault which
triggers when nested acc loop directives are present.
Cesar has reviewed this patch internally (since he mostly wrote
the code originally)

Patch has been tested and committed to gomp-4_0-branch,
is this also okay for trunk?

Thanks,
Chung-Lin

2016-08-15  Chung-Lin Tang  <clt...@codesourcery.com>

        * omp-low.c (lower_oacc_reductions): Adjust variable lookup to use
        maybe_lookup_decl, to handle nested acc loop directives.

Index: omp-low.c
===================================================================
--- omp-low.c   (revision 239324)
+++ omp-low.c   (working copy)
@@ -5687,10 +5687,19 @@ lower_oacc_reductions (location_t loc, tree clause
                outgoing = var;
                incoming = omp_reduction_init_op (loc, rcode, type);
              }
-           else if (ctx->outer)
-             incoming = outgoing = lookup_decl (orig, ctx->outer);
            else
-             incoming = outgoing = orig;
+             {
+               /* Try to look at enclosing contexts for reduction var,
+                  use original if no mapping found.  */
+               tree t = NULL_TREE;
+               omp_context *c = ctx->outer;
+               while (c && !t)
+                 {
+                   t = maybe_lookup_decl (orig, c);
+                   c = c->outer;
+                 }
+               incoming = outgoing = (t ? t : orig);
+             }
              
          has_outer_reduction:;
          }

Reply via email to