https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102985

            Bug ID: 102985
           Summary: [openmp] Bogus "error: lastprivate variable ‘n’ is
                    private in outer context"
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: openmp, rejects-valid
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Shows up at https://github.com/clang-ykt/omptests/ for
t-distribute-simd-clauses/test.c and t-unified-distribute-simd-clauses/test.c

Namely for code like the following:
   error: lastprivate variable ‘n’ is private in outer context

-fdump-tree-gimple shows:
                #pragma omp distribute private(k.0)
                      #pragma omp simd linear(k:1) lastprivate(n)

'distribute' permits 'lastprivate' and OpenMP says "The effect of the
lastprivate clause is as if it is applied to all leaf constructs that permit
the clause. [...]".



void test(int *a, int N)
{
  #pragma omp target map(tofrom: a[0:100])
  {
    #pragma omp teams num_teams(1)
    {
      int n;
      #pragma omp distribute simd lastprivate(n)
      for(int k=0; k<N; k++) {
        a[k] = k;
        n = k;
      }
      a[0] = n;
    }
  }
}


 * * *

For Fortran, it seems to work (original dump):

                    #pragma omp distribute lastprivate(res)
                          #pragma omp simd linear(k:1) lastprivate(res)

but I would still suggest to add a testcase for it.


subroutine sub(a, N)
  implicit none
  integer :: a(0:100), N
  integer :: res, k
  !$omp target map(tofrom: a)
  !$omp teams num_teams(1)
      !$omp distribute simd lastprivate(res)
      do k=0, N
        a(k) = k
        res = k
      end do
      a(0) = res
  !$omp end teams
  !$omp end target
end

Reply via email to