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

            Bug ID: 129178
           Summary: [OpenACC] POINTER DO variable of an !$acc loop is
                    privatized unassociated: segfault
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

Found while fixing PR129176, the OpenMP side of the same problem.

The DO variable of an !$acc loop is predetermined private.  When it has
the POINTER attribute, gfortran privatizes the pointer itself and the
loop body then assigns the DO variable through the private copy, which
is not associated (-fdump-tree-gimple):

  #pragma acc loop private(i.0) private(i)
  for (i.0 = 1; i.0 <= n; i.0 = i.0 + 1)
    {
      *i = i.0;
      ...

Reproducer (gfortran -fopenacc):

program p
  implicit none
  integer, pointer :: i
  integer :: a(100), n
  allocate (i)
  n = 100
  a = 0
  !$acc parallel loop copy(a)
  do i = 1, n
     a(i) = i
  end do
  if (any (a /= [(n, n = 1, 100)])) stop 1
  print *, 'ok'
end program p

Observed:
- AMD GCN offload (GCC 16.2.1, -foffload-options=-march=gfx10-3-generic):
  "Memory access fault by GPU ... on address (nil)" at -O0 and -O2.
- Host (ACC_DEVICE_TYPE=host, or no offloading configured): SIGSEGV at
  -O2; "ok" at -O0 only by chance.

The same happens with !$acc loop seq inside !$acc parallel, and when
the DO variable is a POINTER dummy argument.

Expected: either the loop works or gfortran diagnoses it.  For OpenMP,
the initial status of a private pointer is undefined (OpenMP 4.0,
2.14.3.3), and PR129176 adds a -Wopenmp warning for a POINTER iteration
variable.  I have not found a matching rule in the OpenACC specification, so it
is open whether this wants a diagnostic or code that gives the private pointer
a private target.

I am working on a fix.
  • [Bug fortran/129178] New: [OpenA... jvdelisle at gcc dot gnu.org via Gcc-bugs

Reply via email to