On Fri, Jan 31, 2014 at 09:18:33PM +0400, Ilya Verbin wrote: > 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:
Implicit map(tofrom: a) on #pragma omp target is what the standard requires, so I don't see a bug on the compiler side. I'd need to go back to omp-lang endless discussions regarding the copy_from stuff and/or discuss this further. I'd suggest just using map(tofrom: a[0:N]) also on the #pragma omp target, then it is clear what should happen. Jakub