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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID
            Summary|[OpenMP 4.5] Mapping array  |Mapping array section (e.g.
                   |section (e.g. [0:N-1])      |[0:N-1]) using omp target
                   |using omp target map        |map crashes at runtime
                   |crashes at runtime          |

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That testcase is invalid in OpenMP 4.0/4.5.
  int a1d[N];
#pragma omp target data map(from: a1d[1:])
#pragma omp target map(tofrom: isHost)
  {
    use (a1d[someidx]);
  }
In target data you map 999 elements from a1d[1] to a1d[999], but because there
is no map clause for a1d on the target construct and a1d is referenced in the
construct, there is implicit map(tofrom: a1d) on the target construct.  Because
a1d is already partially mapped, that is then unspecified behavior.

This is going to change in OpenMP 5.0, where the implicit data mapping on
target construct will work differently from explicit data mapping, if there
will be a partial mapping, will just increment counter for that and not invoke
UB.  But OpenMP 5.0 isn't done yet and GCC 8 will not support it either.

To be OpenMP 4.0/4.5 compliant you need to write
#pragma omp target data map(from: a1d[1:])
#pragma omp target map(tofrom: isHost) map(alloc: a1d[1:]) // or from: etc., it
doesn't matter, because it is already mapped;
// or of course you can remove the target data and put map(from: a1d[1:])
directly on the target region, it doesn't buy you anything in this case.

Reply via email to