Looks like there is a bug (in GOMP_target lowering? or in
gomp_map_vars_existing?)
The reproducer:

#define N 1000

void foo ()
{
  int *a = malloc (N * sizeof (int));
  printf ("1: %p\n", a);
  #pragma omp target data map(tofrom: a[0:N])
  {
    printf ("2: %p\n", a);
    #pragma omp target
    {
      int i;
      for (i = 0; i < N; i++)
        a[i] = i;
    }
    printf ("3: %p\n", a);
  }
  printf ("4: %p\n", a);
  free (a);
}

Here GOMP_target believes that the pointer 'a' has a type TOFROM, so
it sets copy_from to true for the existing mapping of the pointer 'a',
that was mapped in GOMP_target_data.  Therefore the output is
incorrect:

1: [host addr]
2: [host addr]
3: [host addr]
4: [target addr]

  -- Ilya

Reply via email to