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

            Bug ID: 90779
           Summary: Fortran array initialization in OpenMP offload regions
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ams at gcc dot gnu.org
  Target Milestone: ---

Initializing arrays (or just assigning them) using implied do loops (or
whatever the proper Fortran name is) does not work within OpenMP "target"
regions. The code parses OK, initially, but the offload compilation fails.

The following testcase demonstrates the problem:

  program main
    implicit none
    integer :: v(4), i

  !$omp target map(from:v)
    v(:) = (/ (i, i=1,4) /)
  !$omp end target
  end program

Here's what a recent GCC trunk build says, when configured for nvptx
offloading:

  testcase.f90:6: error: variable 'A.0' has been referenced in offloaded code
but hasn't been marked to be included in the offloaded code
      6 |   v(:) = (/ (i, i=1,4) /)


Looking at the tree dumps, the Fortran front-end is creating a local static
array "A.0" (that contains {1, 2, 3, 4}) in the host-side function, but then
this goes out of scope in the OpenMP offload kernel that wants to reference it.

The same error message can be provoked in C like this:

  int main() {
    int v = 0;

  #pragma omp target map(v)
    {
      static int a = 1;
      v = a;
    }

    return v;
  }

It's not obvious to me that this is a valid thing to want to do in C, but the
Fortran case absolutely ought to work.

Reply via email to