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

--- Comment #10 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 48522
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48522&action=edit
Patch to add OpenMP 5 feature (private + lastprivate permitted for 'simd')

The patch solves an independent issue, required for the test case below
(namely, the "private(j)").

The *committed* patch causes gfortran.dg/gomp/target1.f90 to FAIL.

The problem shows up with the following test case (reduced but modified):
-------------
  subroutine foo ()
    integer :: s, i, j
    !$omp target teams
    !$omp distribute parallel do default(shared) &
    !$omp collapse (2) private(j) lastprivate (s)
      do i = 1, 10
        do j = 1, 10
          s = i * 10 + j
        end do
      end do
    !$omp end target teams
  end subroutine
-------------

The problem is that this currently produces (-fdump-tree-original):
  #pragma omp teams private(i) private(j)

Which later causes problems as it doesn't add a  (last)private(i) when it
should 

(Search for "if (outer && lastprivate)" in gimplify_omp_for – and look through
the lines below. As "i" is present, omp_check_private() returns true and a
required omp_add_variable is not called. – Leading later to the ICE.)

That's solved by:

--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -5688,3 +5688,3 @@ gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym,
bool add_clause)
       gfc_code *omp_code = omp_current_ctx->code->block;
-      for ( ; omp_code->next; omp_code = omp_code->next)
+      for ( ; omp_code; omp_code = omp_code->next)
        switch (omp_code->op)

However, that leads to the odd result that:

  !$omp target teams
    !$omp distribute parallel do default(shared) &  ! "do"
    !$omp collapse (2) private(j) lastprivate (s)
    ...
    !$omp distribute parallel do simd default(shared) & ! "do simd" (!)
    !$omp collapse (2) private(j) lastprivate (s)
    ...

has "#pragma omp teams" [w/o private(i) private(j)]

While removing the "simd" from the code above leads to no "private(i)
private(j)", which does not make sense.

The code (openmp.c's gfc_do_resolve_do_iterator) is supposed to do:
  /* !$omp do and !$omp parallel do iteration variable is predetermined
     private just in the !$omp do resp. !$omp parallel do construct,
     with no implications for the outer parallel constructs.  */

But here it adds it to 'teams', which looks wrong/inconsistent.

Reply via email to